Re: Expression-local variables and 'let'
Daniel Bonniot <[email protected]> Sun, 22 Feb 2004 00:44:43 +0100
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
>>You can call the body multiple times. 'foreach' is implemented in
>>nice.lang, for instance.
>>Am I missing something?
>>
>>
>
>Yes, you can execute the body multiple times but you can only execute the
>condition once. The type of a 'while' function would be:
> (() -> bool, () -> ()) -> ()
>
>But, the calling syntax only works for a function of type:
> (bool, () -> ()) -> ().
>
>
You're right.
One way to handle this would be to allow a declaration like:
void while(delayed<boolean> condition, delayed<void> body) { ... }
delayed<T> would be basically ()->T, but with the additional rule that
an expression of type T can be used where delayed<T> is expected
(semantically, it is wrapped inside a closure at that point, and so it's
value is not evaluated). It's probably needed to introduce those delayed
types because I would think it's unwise to silently convert from T to
()->T everywhere.
I first thought about using the name lazy<T>, but that's actually a
different concept (once the value is computed, you "cache" it, not
recompute it at each use).
Daniel
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click