How to delete my avatar?
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

  Top users: 
  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:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или законы РФ. Ваш ip-адрес записывается.


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:
[Messaging, JMS & JBossMQ] - Jboss/JMS…
[JBossWS] - Re: what is jbossws…
[Clustering/JBoss] - Load Balancer is…
pass tests:
Do you really know yourself?
see also:
An easy way to convert Mod/Tod video to…
How to burn QuickTime Movie to DVD?

  Copyright © 2001—2010 QAIX
Идея: Монашёв Михаил.
Авторами текстов, изображений и видео, размещённых на этой странице, являются пользователи сайта.
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.
Пишите нам на .
If you would like to report an abuse of our service, such as a spam message, please .
Если Вы хотите пожаловаться на содержимое этой страницы, пожалуйста .