[phobos] static opCall for construction
Philippe Sigaud
philippe.sigaud at gmail.com
Sun May 30 09:10:48 PDT 2010
On Sun, May 30, 2010 at 15:38, Adam Ruppe <destructionator at gmail.com> wrote:
> On 5/30/10, Brad Roberts <braddr at puremagic.com> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100530/ecd82af8/attachment.html>
More information about the phobos
mailing list