Why do the old the old avatars remain after being replaced by the new ones?
Should a closure-in-a-string get the placeholder parameters from its surroundings?
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What is interesting here?
• Duels
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Ñîîáùåñòâà
• Talxy Chat
• Horoscope
• Online
 
Register!

QAIX > Perl web-programming > Should a closure-in-a-string­ get the placeholder parameters from its surroundings? 21 November 2008 23:22:33

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Ìîäåðàòîð:

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

Carl M sak 20 November 2008 23:22:26
 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.perl­geek.de/perl6/2008-1­1-20#i_707971>

// Carl
Add comment
TSa 21 November 2008 11:42:41 permanent link ]
 HaloO,

Carl M sak wrote:
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 just want to make sure that I got the problem right. Would

my $cl = { "$^name upcased becomes {$^OUTER::name.uc}"­ };
say $cl("larry")

work? The idea is that the embedded closure refers to the strings
$^name. And now the dwimmyness shall make that implicit, right?


Regards, TSa.
--

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12 -- Srinivasa Ramanujan
Add comment
Carl M sak 21 November 2008 23:22:33 permanent link ]
 TSa (>):
I just want to make sure that I got the problem right. Would
my $cl = { "$^name upcased becomes {$^OUTER::name.uc}"­ };
say $cl("larry")
work? The idea is that the embedded closure refers to the strings
$^name. And now the dwimmyness shall make that implicit, right?

I guess that should work. I'm not sure how OUTER:: works together with
the hat twigil, but it has all the hallmarks of avoiding the problem,
yes.

// Carl
Add comment
Larry Wall 21 November 2008 23:22:33 permanent link ]
 On Fri, Nov 21, 2008 at 09:42:41AM +0100, TSa wrote:
HaloO,
Carl M sak wrote:
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 just want to make sure that I got the problem right. Would
my $cl = { "$^name upcased becomes {$^OUTER::name.uc}"­ };
say $cl("larry")
work? The idea is that the embedded closure refers to the strings
$^name. And now the dwimmyness shall make that implicit, right?

That seems a bit odd to me, but if $^name merely causes a signature
to be generated that declares $name as a (lexically scope) parameter,
then it's just:

my $cl = { "$^name upcased becomes {$name.uc}" };

But perhaps for clarity you would just write:

my $cl = { "$^name upcased becomes $^name.uc()" };

Larry
Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
respect your talk pals, avoid using obscene language, typing entire messages in CAPS, posting buy/sell ads or violating netiquette or the RF Criminal Code..


QAIX > Perl web-programming > Should a closure-in-a-string­ get the placeholder parameters from its surroundings? 21 November 2008 23:22:33

see also:
how can I multi-region my pc's DVD-rom
Forgotten & The Grudge looses 1st…
Multi-Currency Support
pass tests:
see also:
Do you hear...
Am i mad
The prayer i prayed evry day

  Copyright © 2001—2009 QAIX
Idea: Miñhael Monashev
See Help and FAQ in the community support.qaix.com.
Write in the community about the bugs you have noticedbugs.qaix.com.
Write your offers and comments in the communities suggest.qaix.com.
Information for parents.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .