Re: Dispatching on a variant

2009-09-26 Thread Jarrett Billingsley
On Sat, Sep 26, 2009 at 10:36 AM, Justin Johansson proc...@adam-dott-com.au wrote: I've got about 2 dozen types in the variant so the O(n) really hurts. The variant thing seemed like a really cool idea at the time but now ... Without something like suggested above or a computed goto on typeid

Re: Dispatching on a variant

2009-09-26 Thread Lutger
Justin Johansson wrote: ... I've got about 2 dozen types in the variant so the O(n) really hurts. The variant thing seemed like a really cool idea at the time but now ... Without something like suggested above or a computed goto on typeid or Andrei's visitator, it almost pushes me to

Re: Dispatching on a variant

2009-09-26 Thread language_fan
Sat, 26 Sep 2009 09:32:55 -0400, Justin Johansson thusly wrote: I've had a good poke around the forums and couldn't find anything on this so ... What's the recommended method for dispatching code off the runtime type of a variant variable (Phobos D2 std.variant)? Does one use a bunch of

Re: Dispatching on a variant

2009-09-26 Thread Jeremie Pelletier
Justin Johansson wrote: language_fan Wrote: Sat, 26 Sep 2009 09:32:55 -0400, Justin Johansson thusly wrote: I've had a good poke around the forums and couldn't find anything on this so ... What's the recommended method for dispatching code off the runtime type of a variant variable (Phobos

Dispatching on a variant

2009-09-26 Thread Justin Johansson
I've had a good poke around the forums and couldn't find anything on this so ... What's the recommended method for dispatching code off the runtime type of a variant variable (Phobos D2 std.variant)? Does one use a bunch of if ( var.peek!(type1)) { ... } else if ( var.peek!(type2) { ... }

Re: Dispatching on a variant

2009-09-26 Thread Justin Johansson
language_fan Wrote: Sat, 26 Sep 2009 09:32:55 -0400, Justin Johansson thusly wrote: I've had a good poke around the forums and couldn't find anything on this so ... What's the recommended method for dispatching code off the runtime type of a variant variable (Phobos D2 std.variant)?

Re: Dispatching on a variant

2009-09-26 Thread Andrei Alexandrescu
Justin Johansson wrote: I've had a good poke around the forums and couldn't find anything on this so ... What's the recommended method for dispatching code off the runtime type of a variant variable (Phobos D2 std.variant)? Does one use a bunch of if ( var.peek!(type1)) { ... } else if (

Re: Dispatching on a variant

2009-09-26 Thread language_fan
Sat, 26 Sep 2009 12:25:23 -0400, Jeremie Pelletier thusly wrote: Justin Johansson wrote: language_fan Wrote: Sat, 26 Sep 2009 09:32:55 -0400, Justin Johansson thusly wrote: I've had a good poke around the forums and couldn't find anything on this so ... What's the recommended method for

Re: Dispatching on a variant

2009-09-26 Thread language_fan
Sat, 26 Sep 2009 18:28:52 +0200, Lutger thusly wrote: a hash literal works like this, index with the typeid to get a function ptr you can call: Algebraic!(int, Foo) a; a = 3; [ typeid(int) : function { writeln(a is int); }, typeid(Foo) : function { writeln(a is Foo); } ] [a.type] ();

Re: Dispatching on a variant

2009-09-26 Thread Jeremie Pelletier
language_fan wrote: Sat, 26 Sep 2009 12:25:23 -0400, Jeremie Pelletier thusly wrote: Justin Johansson wrote: language_fan Wrote: Sat, 26 Sep 2009 09:32:55 -0400, Justin Johansson thusly wrote: I've had a good poke around the forums and couldn't find anything on this so ... What's the

Re: Dispatching on a variant

2009-09-26 Thread Jarrett Billingsley
On Sat, Sep 26, 2009 at 4:18 PM, Jeremie Pelletier jerem...@gmail.com wrote:  type Event = Mouse | Key | Move; This can be confusing, for example the first thing that comes to mind for me is that Event is the bitwise OR result of 3 constants, not an enumerated type. Besides, how is it any

Re: Dispatching on a variant

2009-09-26 Thread Jeremie Pelletier
Jarrett Billingsley wrote: On Sat, Sep 26, 2009 at 4:18 PM, Jeremie Pelletier jerem...@gmail.com wrote: type Event = Mouse | Key | Move; This can be confusing, for example the first thing that comes to mind for me is that Event is the bitwise OR result of 3 constants, not an enumerated type.

Re: Dispatching on a variant

2009-09-26 Thread Jarrett Billingsley
On Sat, Sep 26, 2009 at 4:50 PM, Jeremie Pelletier jerem...@gmail.com wrote: Oh, that makes sense, but I don't see why you need language support for that, a variant type should be able to get most of it using type tuples, maybe just add support to switch on type tuples along with an opSwitch()

Re: Dispatching on a variant

2009-09-26 Thread language_fan
Sat, 26 Sep 2009 16:50:36 -0400, Jeremie Pelletier thusly wrote: Jarrett Billingsley wrote: On Sat, Sep 26, 2009 at 4:18 PM, Jeremie Pelletier jerem...@gmail.com wrote: type Event = Mouse | Key | Move; This can be confusing, for example the first thing that comes to mind for me is that

Re: Dispatching on a variant

2009-09-26 Thread #ponce
Exactly, this is what I mentioned previously. Isn't it ugly compared to type Event = Mouse | Key | Move; void dispatchEvent(Event event) { match(event) { Mouse m = m.squeek(); Key k = ... ... } } What's with all the language proposals here? Why

Re: Dispatching on a variant

2009-09-26 Thread Justin Johansson
Jarrett Billingsley Wrote: On Sat, Sep 26, 2009 at 10:36 AM, Justin Johansson proc...@adam-dott-com.au wrote: I've got about 2 dozen types in the variant so the O(n) really hurts. The variant thing seemed like a really cool idea at the time but now ... Without something like suggested

Re: Dispatching on a variant

2009-09-26 Thread Andrei Alexandrescu
Justin Johansson wrote: At the end of the day, if I can get this thing to fly using D, it will, at least to me, prove that D is a killer language. One way or another you will, and if you have difficulties let us hear of them. Practical experience with Algebraic and friends is very valuable.

Re: Dispatching on a variant

2009-09-26 Thread Christopher Wright
Justin Johansson wrote: I've had a good poke around the forums and couldn't find anything on this so ... What's the recommended method for dispatching code off the runtime type of a variant variable (Phobos D2 std.variant)? Does one use a bunch of if ( var.peek!(type1)) { ... } else if (

Re: Dispatching on a variant

2009-09-26 Thread language_fan
Sat, 26 Sep 2009 18:51:19 -0400, #ponce thusly wrote: Exactly, this is what I mentioned previously. Isn't it ugly compared to type Event = Mouse | Key | Move; void dispatchEvent(Event event) { match(event) { Mouse m = m.squeek(); Key k = ... ... } }

Re: Dispatching on a variant

2009-09-26 Thread Justin Johansson
Andrei Alexandrescu Wrote: Justin Johansson wrote: At the end of the day, if I can get this thing to fly using D, it will, at least to me, prove that D is a killer language. One way or another you will, and if you have difficulties let us hear of them. Practical experience with

Re: Dispatching on a variant

2009-09-26 Thread Justin Johansson
Christopher Wright Wrote: Justin Johansson wrote: I've had a good poke around the forums and couldn't find anything on this so ... What's the recommended method for dispatching code off the runtime type of a variant variable (Phobos D2 std.variant)? Does one use a bunch of

Re: Dispatching on a variant

2009-09-26 Thread Andrei Alexandrescu
Christopher Wright wrote: Justin Johansson wrote: I've had a good poke around the forums and couldn't find anything on this so ... What's the recommended method for dispatching code off the runtime type of a variant variable (Phobos D2 std.variant)? Does one use a bunch of if (

Re: Dispatching on a variant

2009-09-26 Thread Jeremie Pelletier
Christopher Wright wrote: Justin Johansson wrote: I've had a good poke around the forums and couldn't find anything on this so ... What's the recommended method for dispatching code off the runtime type of a variant variable (Phobos D2 std.variant)? Does one use a bunch of if (

Re: Dispatching on a variant

2009-09-26 Thread Jarrett Billingsley
On Sat, Sep 26, 2009 at 11:16 PM, Jeremie Pelletier jerem...@gmail.com wrote: string switch actually walks the case strings and compares with the source string until it finds a match, a binary search is much faster if you don't care about the order of the tests. FWIW the runtime does perform

Re: Dispatching on a variant

2009-09-26 Thread Jeremie Pelletier
Jarrett Billingsley wrote: On Sat, Sep 26, 2009 at 11:16 PM, Jeremie Pelletier jerem...@gmail.com wrote: string switch actually walks the case strings and compares with the source string until it finds a match, a binary search is much faster if you don't care about the order of the tests.