Re: Catching signals with D

2011-12-22 Thread Heywood Floyd
On 12/22/11 23:51 , Matej Nanut wrote: Hello everyone, I've been fascinated by D lately and have been using it for all my school assignments (like simple ray casting and simulated annealing). What I can't find anywhere is how to do something like "signal(SIGINT, myhandler)" (I'm in a Linux envir

Catching signals with D

2011-12-22 Thread Matej Nanut
Hello everyone, I've been fascinated by D lately and have been using it for all my school assignments (like simple ray casting and simulated annealing). What I can't find anywhere is how to do something like "signal(SIGINT, myhandler)" (I'm in a Linux environment). I need this to stop the anneali

Re: ctfe bug?

2011-12-22 Thread Johannes Pfau
Jacob Carlborg wrote: > On 2011-12-22 14:39, Timon Gehr wrote: >> On 12/22/2011 10:28 AM, Jacob Carlborg wrote: >>> On 2011-12-22 08:47, Johannes Pfau wrote: Hi, the following code is reduced from a parser generated with Ragel (http://www.complang.org/ragel/). That's also the reason

Re: test if object is instance of class at compile time

2011-12-22 Thread Andrew Wiley
On Thu, Dec 22, 2011 at 8:35 AM, Trass3r wrote: > I'd really like to have 'if (instance is ClassType)' syntax in D. It couldn't use that syntax because 'is' means direct bitwise equality everywhere else. Changing it in this one situation would be awkward.

Re: newbie question: can D do this?

2011-12-22 Thread Philippe Sigaud
On Thu, Dec 22, 2011 at 16:45, clk wrote: > Philippe, > I don't understand the example below to simulate the list comprehension > syntax.  Are input1, input2 and input3 ranges? Yes, inputs are ranges. Sorry, I was perhaps a bit hasty in answering. The code is on github: https://github.com/Philip

Re: test if object is instance of class at compile time

2011-12-22 Thread Trass3r
I'd really like to have 'if (instance is ClassType)' syntax in D.

Re: newbie question: Can D do this?

2011-12-22 Thread Philippe Sigaud
On Thu, Dec 22, 2011 at 16:37, clk wrote: > Philippe, > Thank you very much for your response.  It looks similar to what I've done > in javascript by wrapping all function arguments into a single object > literal but the D alternative you propose is a little to convoluted for a > beginner like me.

Re: test if object is instance of class at compile time

2011-12-22 Thread Elvis Maehren
Timon Gehr wrote: > On 12/21/2011 09:15 PM, Elvis Maehren wrote: [...] >> Moreover, in CTFE a failed cast terminates the interpretation ("cannot >> reinterpret class from [...] to [...] at compile time"). > > I don't think this is filed already. Maybe you want to file a bug report? ok, did that:

Re: newbie question: can D do this?

2011-12-22 Thread clk
Philippe, I don't understand the example below to simulate the list comprehension syntax. Are input1, input2 and input3 ranges? Where is the comp function defined? Thank you, -clk (Christian Keppenne) auto lc = comp!("tuple(a,b,c)", "a*a+b*b == c*c&& a -- Messa

Re: newbie question: Can D do this?

2011-12-22 Thread clk
Philippe, Thank you very much for your response. It looks similar to what I've done in javascript by wrapping all function arguments into a single object literal but the D alternative you propose is a little to convoluted for a beginner like me. Perhaps I'll understand it better after I'm don

Re: ctfe bug?

2011-12-22 Thread Jacob Carlborg
On 2011-12-22 14:39, Timon Gehr wrote: On 12/22/2011 10:28 AM, Jacob Carlborg wrote: On 2011-12-22 08:47, Johannes Pfau wrote: Hi, the following code is reduced from a parser generated with Ragel (http://www.complang.org/ragel/). That's also the reason why it's using pointers instead of array a

Re: ctfe bug?

2011-12-22 Thread Timon Gehr
On 12/22/2011 10:28 AM, Jacob Carlborg wrote: On 2011-12-22 08:47, Johannes Pfau wrote: Hi, the following code is reduced from a parser generated with Ragel (http://www.complang.org/ragel/). That's also the reason why it's using pointers instead of array access, but Ragel guarantees that there w

Re: test if object is instance of class at compile time

2011-12-22 Thread Timon Gehr
On 12/21/2011 09:15 PM, Elvis Maehren wrote: This works fine at runtime, but explodes in CTFE: --- bool isInstanceOf(T, O)(O o) { return (cast(T) o) !is null; } --- CTFE doesn't like "!is null" ("cannot compare [...] at compile time"). This will be fixed in the next release: http://d

onStartTag for root node in std.xml

2011-12-22 Thread Heromyth
In the test code, the onStartTag will not be called for the root node "set". The onEndTag is OK, and the onStartTag is OK for sub nodes. Is this a bug, or just it is? Can anybody confirm it? Thanks. // test.d module main; import std.string; import std.stdio; import std.xml; int main(string[] a

Re: ctfe bug?

2011-12-22 Thread Johannes Pfau
Jacob Carlborg wrote: > On 2011-12-22 08:47, Johannes Pfau wrote: >> Hi, >> the following code is reduced from a parser generated with Ragel >> (http://www.complang.org/ragel/). That's also the reason why it's >> using pointers instead of array access, but Ragel guarantees that there >> won't be a

Re: test if object is instance of class at compile time

2011-12-22 Thread Elvis Maehren
Jacob Carlborg wrote: > On 2011-12-21 21:15, Elvis Maehren wrote: >> This works fine at runtime, but explodes in CTFE: >> --- >> bool isInstanceOf(T, O)(O o) { >> return (cast(T) o) !is null; >> } >> --- >> [...] > I don't think you can do a test like that during compile time. In your > above funct

Re: test if object is instance of class at compile time

2011-12-22 Thread Elvis Maehren
Vladimir Panteleev wrote: > I believe that's what __traits(compiles, ...) is for: __traits(compiles, cast(T) o) is true even if the cast blows up in CTFE, so that doesn't work.

Re: ctfe bug?

2011-12-22 Thread Jacob Carlborg
On 2011-12-22 08:47, Johannes Pfau wrote: Hi, the following code is reduced from a parser generated with Ragel (http://www.complang.org/ragel/). That's also the reason why it's using pointers instead of array access, but Ragel guarantees that there won't be any out-of-bound reads. AFAIK pointers

Re: writing iterators without code duplication. inout?

2011-12-22 Thread Andrew Wiley
On Thu, Dec 22, 2011 at 12:04 AM, pompei2 wrote: >> int delegate(int delegate(ref int)) doIter() const >>  { >> 74      return (int delegate(ref int) dg) >>      { >>        cast(typeof(this))(this).doIter() >> 77            ( >> 78              (ref int i) >> >>              { >>                i

Re: writing iterators without code duplication. inout?

2011-12-22 Thread pompei2
int delegate(int delegate(ref int)) doIter() const { 74 return (int delegate(ref int) dg) { cast(typeof(this))(this).doIter() 77( 78 (ref int i) { int copy = i; dg(copy); } ); } } I see w

Re: ctfe bug?

2011-12-22 Thread Johannes Pfau
Johannes Pfau wrote: > > Has this bug already been filed? I could possibly circumvent it by making > ragel use array indexing instead of pointers, but that'd be a performance > issue for runtime code as well. OK, I found a workaround: If I use data[x] = parse!ubyte(input[p-input