Why Ruby?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sat Dec 18 20:05:44 PST 2010
Argh it started a new topic. Disregard this I'll reply to original thread.
On 12/19/10, Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:
> On 12/19/10, Nick Sabalausky <a at a.a> wrote:
>>
>> int foo(int x) { ... }
>> map!"foo(a) * 2" // Trivial lambda, but it fails
>
> Currently this will call unaryFunImpl, which tries to evaluate foo(a)
> at compile-time, but foo isn't visible from std.functional, where
> unaryFunImpl is defined.
>
> I don't know, maybe Phobos could construct a closure out of the string
> somehow if it detected that there's a function call in that string,
> here's some pseudocode modified from std.functional:
>
> template unaryFunImpl(alias fun, bool byRef, string parmName = "a")
> {
> static if (is(typeof(fun) : string))
> {
> // added: detect if there's a function call in that string
> static if (hasFunctionCalls(fun))
> {
> // if so construct a closure, and that should be it
> alias newclosure result;
> }
> else
> {
> // Otherwise do as usual in std.functional.unaryFunImpl
> template Body(ElementType)
> {
> }
> // old code...
> }
> }
> else
> {
> alias fun result;
> }
> }
>
More information about the Digitalmars-d
mailing list