foo!(bar) ==> foo{bar}
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Oct 7 13:47:30 PDT 2008
Simen Kjaeraas wrote:
> On Mon, 06 Oct 2008 23:24:01 +0200, superdan <super at dan.org> wrote:
>
>> Nick Sabalausky Wrote:
>>
>>> "Walter Bright" <newshound1 at digitalmars.com> wrote in message
>>> news:gcdqa4$qas$1 at digitalmars.com...
>>> > The foo.(bar) syntax seems to be sinking. The foo{bar} seems to be the
>>> > most practical alternative. So, how about putting it in the next D2
>>> > release on a trial basis, so people can try it out and see how it
>>> looks?
>>>
>>> I would like to eventually be able to have a function like this (trivial
>>> contrived example):
>>>
>>> repeat(int times, void delegate() d)
>>> {
>>> foreach(int i; 0..times)
>>> d();
>>> }
>>>
>>> And call it like this:
>>>
>>> repeat(3)
>>> {
>>> // Do stuff
>>> }
>>>
>>> Instead of needing to use the current awkwardness of:
>>>
>>> repeat(3,
>>> {
>>> // Do stuff
>>> });
>>>
>>> If changing "foo!(bar)" to "foo{bar}" would cause problems with that,
>>> then
>>> I'd be against it. Otherwise, I'd be ok with the change, provided
>>> that it
>>> didn't end up becoming visually confusing in terms of "Is that a big
>>> template parameter list, or a statement block?"
>>
>> nagonna be a problem. it's been discussed. id { stuff }is
>> instantiation. id(optional stuff) { stuff } is that thing yer talkin'
>> about.
>
> Not necessarily. Consider
>
> repeat(int times = 3, void delegate() d){...}
>
> repeat
> {
> foo();
> }
>
I think that's a corner case we shouldn't cater for. Most of the time
you want to pass parameters into the delegate. Therefore the delegate
will have to be somehow prefixed by a parameter declaration, which will
syntactically disambiguate it.
Andrei
More information about the Digitalmars-d
mailing list