develooper Front page | perl.perl6.language | Postings from November 2008

Should a closure-in-a-string get the placeholder parameters from its surroundings?

Thread Next
From:
Carl Mäsak
Date:
November 20, 2008 14:18
Subject:
Should a closure-in-a-string get the placeholder parameters from its surroundings?
Message ID:
16d769b70811201417r7b6b1fc3n794f3cc6df90f0fd@mail.gmail.com
I expected this to DWIM today:

$ perl6 -e 'my $cl = { "$^name upcased becomes {$^name.uc}" }; say $cl("larry")'

...but it doesn't in Rakudo r32938:

too few arguments passed (0) - 1 params expected

...and for understandable (if not good) reasons: the closure inside
the string expects a parameter ($^name), which it isn't getting.

I'll let the IRC discussion[1] take over from here:

<moritz_> why shouldn't it work?
<masak> moritz_: because the thing inside the string is also a closure.
<moritz_> ah, I see what you mean.
<moritz_> but since you can't pass arguments to closures in strings,
it makes most sense to use the outer closure's self-declared
parameters
<moritz_> I don't know if it's specced, from a dwim'miness POV it should work.
<masak> aye
<jnthn> I could also argue that keeping placeholder parameter
semantics consistent is desirable, and saying that if you want a
closure that takes parameters you can always do a pointy instead.
<jnthn> But yes, I see the other argument too.

[1] slightly redacted for readability. Original here:
<http://irclog.perlgeek.de/perl6/2008-11-20#i_707971>

// Carl

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About