Re: $value but lexically ...
[EMAIL PROTECTED] wrote: Would this work too? 0 but role {} Most certainly, but you would have no way to refer to that role later, so it is questionable how useful that construct is. No, it's not questionable. That is a useless construct. Luke Can an inline role be named? 0 but role is_default {} Miro
Re: $value but lexically ...
Miroslav Silovic skribis 2005-10-07 13:07 (+0200): Can an inline role be named? 0 but role is_default {} This is a nice idea. It would require named roles (and to really be succesful, also classes, subs, methods, ...) declarations to be expressions, but I see no downside to that. Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html
Re: $value but lexically ...
On 10/7/05, Juerd [EMAIL PROTECTED] wrote: Miroslav Silovic skribis 2005-10-07 13:07 (+0200): Can an inline role be named? 0 but role is_default {} This is a nice idea. It would require named roles (and to really be succesful, also classes, subs, methods, ...) declarations to be expressions, but I see no downside to that. Well, I see a cognitive downside. That is, package declarations (the default) don't create closures. It's like this: sub foo($x) { sub bar() { return $x; } return bar; } foo(42).(); # Restricting expressions to anonymous subs forces you to say what you mean. Because sometimes when you say: 0 but role is_default { } You're going to mean package role, and some of the time you're going to mean lexical. I'd be more in favor of: 0 but my role is_default { } In fact, it may be the case that that's already valid. Luke
Re: $value but lexically ...
Luke Palmer skribis 2005-10-07 15:31 (-0600): Well, I see a cognitive downside. That is, package declarations (the default) don't create closures. It's like this: sub foo($x) { sub bar() { return $x; } return bar; } foo(42).(); # Does this mean that this Perl 5 snippet no longer does the same in Perl 6? { my $foo = 5; sub bar { return $foo; } } Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html
Re: $value but lexically ...
On 10/7/05, Juerd [EMAIL PROTECTED] wrote: Luke Palmer skribis 2005-10-07 15:31 (-0600): sub foo($x) { sub bar() { return $x; } return bar; } foo(42).(); # Does this mean that this Perl 5 snippet no longer does the same in Perl 6? { my $foo = 5; sub bar { return $foo; } } Uh no. Okay, when I said that they don't close, I guess I meant they don't close like anonymous routines do. It works precisely like Perl 5's: sub foo { my $foo = 5; sub bar { return $foo; } return \bar; } I don't think I've ever seen that used in Perl 5. Closing over that $foo doesn't mean anything. That's why we're allowing my before such declarations now, so that they can close over something useful. Luke
Re: $value but lexically ...
On Fri, Oct 07, 2005 at 03:46:02PM -0600, Luke Palmer wrote: Uh no. Okay, when I said that they don't close, I guess I meant they don't close like anonymous routines do. It works precisely like Perl 5's: sub foo { my $foo = 5; sub bar { return $foo; } return \bar; } I don't think I've ever seen that used in Perl 5. Closing over that $foo doesn't mean anything. Well strictly speaking it means that bar() captures the first instance of foo()'s $foo, which isn't often very useful. -- The Enterprise successfully ferries an alien VIP from one place to another without serious incident. -- Things That Never Happen in Star Trek #7
$value but lexically ...
Cbut properties get attached to a value, and are available when the value is passed to other functions/ etc. I would like to be able to define a property of a value that is trapped in the lexical scope where it is defined. The example that set me thinking down this path is sub foo( $a, ?$b = rand but :is_default ) { ... bar($a,$b); } sub bar( $a, ?$b = rand but :is_default ) { warn defaulting \$b = $b if $b.is_default; ... } It would be unfortunate if the is_default property attached in foo triggers the warning in bar. So I'd like to say somthing like sub foo( $a, ?$b = 0 but lexically :is_default ) {...} or sub foo( $a, ?$b = 0 but locally :is_default ) {...} to specify that I don't want the property to the propagated.
Re: $value but lexically ...
On 10/6/05, Dave Whipp [EMAIL PROTECTED] wrote: sub foo( $a, ?$b = rand but :is_default ) { ... bar($a,$b); } sub bar( $a, ?$b = rand but :is_default ) { warn defaulting \$b = $b if $b.is_default; ... } It would be unfortunate if the is_default property attached in foo triggers the warning in bar. So I'd like to say somthing like sub foo( $a, ?$b = 0 but lexically :is_default ) {...} or sub foo( $a, ?$b = 0 but locally :is_default ) {...} to specify that I don't want the property to the propagated. This came up before when I proposed lexical properties. That was before we knew that a property was just a role. So you can do a lexical property like so: { my role is_default {} # empty sub foo($a, ?$b = 0 but is_default) {...} } { my role is_default {} sub bar($a, ?$b = rand but is_default) {...} } If this turns out to be a common want, I can see: sub bar($a, ?$b = rand but my $is_default) { warn Defaulted to $b if $b.does($is_default); } But I don't think it will be, and the empty role is easy enough. Luke
Re: $value but lexically ...
Luke Palmer skribis 2005-10-06 14:23 (-0600): my role is_default {} # empty sub foo($a, ?$b = 0 but is_default) {...} Would this work too? 0 but role {} Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html
Re: $value but lexically ...
On 10/6/05, Juerd [EMAIL PROTECTED] wrote: Luke Palmer skribis 2005-10-06 14:23 (-0600): my role is_default {} # empty sub foo($a, ?$b = 0 but is_default) {...} Would this work too? 0 but role {} Most certainly, but you would have no way to refer to that role later, so it is questionable how useful that construct is. No, it's not questionable. That is a useless construct. Luke