Re: return() in pointy blocks
by =22TSa_=28Thomas_Sandla=DF=29=22 other posts by this author
Jun 8 2005 1:57AM messages near this date
Re: return() in pointy blocks
|
Re: return() in pointy blocks
Luke Palmer wrote:
> Says not:
>
> Boo
> Boo
> Boo
> ...
This is clear, but I would expect the output
Boo
42
because the return value of foo is a ref to a block that
makes the caller return 42. This is written in my current
Perl6 as
&foo:( : --> Block --> 42)
The question is when exactly this call chain is invoked:
1) when it is assigned to $code? Or,
2) when &postfix:<( )> is invoked on $code?
I prefer 2) because it better fits my understanding of
referential semantics. About the relationship to the lazy
versus eager trade-off I'm unsure. So 1) is also a good
choice.
With this in mind, I wonder how \ and -> are related. Is
$x = 3;
$rw = -> $x;
valid syntax? And does it mean that
$rw = 7;
say $x; # prints 7
This can be construed as the eager version of
$x = 3;
$rw = -> { $x };
$rw = 7;
say $x; # means: say $x();
A block in a chain of references is a stop mark in a chain of refs.
$x = 3;
$r = -> $x;
$rr = -> $r;
say $rr(); # prints 3, because say $r; also prints 3
$rr = 7;
say $r; # prints 7
say $x; # prints 3
Looks like we have found a candidate for the transparent ref creator!
And I hope Juerd likes it. After all it looks *pointy* :)
PS: A chain of refs can thus be reduced to the leaf lvalue with
([()] $rr) = 23; which stores a new value in $x. This might even
warrant the special case of ([] $rr) = 23;
--
TSa (Thomas Sandlaß)
Thread:
Ingo Blechschmidt
Matt Fowles
Luke Palmer
=22TSa_=28Thomas_Sandla=DF=29=22
=22TSa_=28Thomas_Sandla=DF=29=22
Larry Wall
"TSa (Thomas Sandlaß)"
Larry Wall
Matt Fowles
|