DMD 0.161 release
Bruno Medeiros
brunodomedeirosATgmail at SPAM.com
Sat Jul 1 03:17:47 PDT 2006
Oskar Linde wrote:
> Walter Bright wrote:
>> Jarrett Billingsley wrote:
>>> "Walter Bright" <newshound at digitalmars.com> wrote in message
>>> news:e7832r$g4h$1 at digitaldaemon.com...
>>>> Mostly bug fixes.
>>>>
>>>> http://www.digitalmars.com/d/changelog.html
>>>
>>> Oh man, those delegate literals look like it would be very possible
>>> to make interesting "pseudo-structures," that is, fake language
>>> constructs. So if you were to define a function as
>>>
>>> void func(void delegate() dg);
>>>
>>> That is, the last parameter is a void delegate(), it would be an
>>> interesting bit of syntactic sugar to be able to write
>>>
>>> func
>>> {
>>> writefln("foo");
>>> }
>>>
>>> Not sure what utility this would present, but hey!
>>
>> There was some thought about doing that, but I'm not so sure it
>> wouldn't be more confusing than useful.
>
> With the new delegate syntax, and a very simple function one can finally
> replace the annoying and common case where a for-loop until now still
> has to be used:
>
> void repeat(Int,Delegate)(Int n, Delegate d) {
> static assert(is(Int:int),"Argument 1 to repeat must be int");
> for (int i = 0; i < n; i++)
> d();
> }
>
> The implementation could also contain:
> static if (NumberOfArgs!(Delegate) == 1)
> d(i);
>
> The use is:
>
> repeat(10, { something(); });
>
> And the multi-line version becomes:
>
> repeat(10, {
> something();
> somethingElse();
> });
>
> Which at least makes me wish for Jarretts suggested short form:
>
> repeat(10) {
> something();
> somethingElse();
> }
>
> But the implications of having such power is almost scary... :)
>
> /Oskar
That's too much power for us puny mortals! :P
--
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d-announce
mailing list