On Sun, May 30, 2010 at 15:38, Adam Ruppe <[email protected]> wrote:

> On 5/30/10, Brad Roberts <[email protected]> wrote:
> > I'm all for removal of static opCall, and possibly opCall altogether.
>
> Removing static opCall is definitely a good plan, but I'd like to keep
> opCall. The reason is so you can make a Variant that holds a delegate,
> and is callable directly.
>


Even more generally, anytime you want a callable struct (well, doh!), to
manage some complex state.
Sometimes, closures don't cut it.

For example, I like that in Clojure all data structures are functions of
their elements, returning true if the element is already present. Handy to
filter. In D, you can wrap a struct around an associative array and define
opCall(E elem) to test if (elem in aa).
Then, you can do:

auto a = filter!( [test for some elements]) (range);



> I tried implementing this a while ago, but it didn't work very well
> because sometimes the compiler would call the static opCall instead of
> the one I wanted! Keeping it around, but only for the one task, would
> be nice to me.
>

I also had troubles with struct with an opCall and a this and couldn't
explain to the compiler what I wanted. I had to use an .initialize() method
to create the struct, to keep () for opCall.
_______________________________________________
phobos mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/phobos

Reply via email to