June 28, 2007
Regan Heath wrote:
> Is such a thing possible in D, function literals.  You might need to explicitly say 'function' in there somewhere.  I've not used these a heck of a lot so I'm not sure.

Yes, function literals are possible. And indeed, they have 'function' in them. In fact, put 'function' in front of a delegate literal (and remove the optional 'delegate' if present) and you have a function literal.

Details: http://www.digitalmars.com/d/expression.html#FunctionLiteral (or the equivalent 1.0 page)
June 28, 2007
BCS Wrote:

> OF wrote:
> > It hints at lazyexp not being valid after the function has ended, which makes it quite different from delegates.
> 
> This is the /exact/ behavior of delegate liters and delegates formed from nested functions. They are invalid after the function call they are from returns. This is because the delegate caries a pointer to the stack frame of the surrounding function.

Yes, you're right. It's probably the delegate created in

this(lazy T exp)
{
	mExp = { return exp(); };
}

that's the problem.

this(T delegate() exp)
{
	mExp = { return exp(); };
}

crashes too. That's what I get for not doing my homework...

I suppose my only hope would be some kind of casting from lazy T to T delegate(), but seems I'm out of luck.
June 28, 2007
"David B. Held" <dheld@codelogicconsulting.com> wrote in message

> ...yet.

So just how far is Walter going to go to please C++ programmers?  :P


June 29, 2007
Jarrett Billingsley wrote:
> "David B. Held" <dheld@codelogicconsulting.com> wrote in message
> 
>> ...yet.
> 
> So just how far is Walter going to go to please C++ programmers?  :P 

The problem is proxy types.  Proxy types happen to be useful, and in order for them to work properly, you basically need implicit casts. Want an example of proxy types not quite working properly?  Think what happens when you do ++ on a property or think of the magic that happens when you do it on a builtin hash.  That doesn't mean they will be implemented just like C++'s implicit casts; but if they fix these other holes in the language, as well as enabling a new pattern, isn't that a net win?

Dave
June 29, 2007
"OF" <nospam@nospammington.com> wrote in message news:f5u09a$1mmq$1@digitalmars.com...
> Hey.  I've been writing a bit on a "true" lazy evaluation (i.e.
> not evaluated until value is requested, but only evaluated once).
> A simple example of this can be achieved using a delegate, like so:
<snip>
> Which would work fine with Lazy!(int)( { return someExpr; } ), but
> it would be nice to be able to just use Lazy!(int)( someExpr ).
> However, it seems this can only be achieved using lazy function
> arguments, but problem is, if I use lazy function arguments, I
> can't really save it for later and do anything worthwhile with it.
<snip>

Actually you can take advantage of the fact that lazy expressions can be used for variadic delegate parameters.

   this(T delegate()[1] exp...)
   {
       mExp = exp;
   }

enables you to use

  Lazy!(int)(someExpr)

I used this to make an Unlambda to D compiler, and it even made it straightforward to implement the d builtin (which David Madore thought would be very hard to compile).  Now the only thing that's left is getting c working properly.

Stewart. 

1 2
Next ›   Last »