D2's std.algorithm
Craig Black
cblack at ara.com
Wed Dec 12 10:04:07 PST 2007
"Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message
news:fjmol3$1f71$1 at digitalmars.com...
> Craig Black wrote:
>> "Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message
>> news:fjl4fo$8am$1 at digitalmars.com...
>>>> sort!("a > b")(array);
>>> I just wanted to say that this is BRILLIANT! Zero call overhead, zero
>>> syntax overhead, compile-time lambda functions!
>>>
>>> All the algorithms should support this syntax so we can do sexy
>>> compile-time lambda one-liners like:
>>>
>>> find!("a.some_member > 10")(array);
>>>
>>> or
>>>
>>> partition!("a.call_something() !is null")(array);
>>>
>>> etc.
>>>
>>> And probably those should allow a data arg passed as 'b' to the lambda
>>> function so you could do something like
>>> find!("a.some_member > b")(array, 10);
>>>
>>> Or even use template varargs and number the args automatically to allow:
>>>
>>> find!("a.x > b && a.w < c")(array, 10, 20);
>>>
>>> It would just sequentially name the arguments b,c,d,e... etc.
>>>
>>> Or even make it like C#/Tango's format string patterns since the string
>>> can be processed before mixing it in.
>>> find!("a.x > {1} && a.w < {2}")(array, 10, 20);
>>>
>>> That would be excellent. Take that boost::lambda!
>>>
>>> --bb
>>
>> Yes very cool! Would be even better if the parens could be removed.
>> Ideally, the compiler would be able to do CTFE with some lambdas.
>
> There's that idea of creating "static" parameters from DCon07.
>
> With that you should be able to stick the string in as a regular
> parameter. But I don't actually find the template syntax too bad. It's a
> good reminder that the argument must be a compile-time constant.
>
> When/if we get static parameters it's going to be harder to tell from
> looking at code what's compile-time and what's not. I anticipate wasting
> lots of time in this manner: "why did I/they write this function like
> this? thats silly <rewrite rewrite> -- oh damn, I see why now. Argument
> #3 has to be a compile-time constant."
>
> --bb
First I've heard about static parameters Very good idea.
You may be right about all that, but I still prefer a syntax without double
quotes.
More information about the Digitalmars-d
mailing list