On Tue, 2005-05-10 at 15:52, Joshua Gatcomb wrote: > I am wondering what the proper behavior of binding to a sub's return > value should be > > sub some_routine { > my $foo = 42; > return $foo; > } > my $rv := some_routine(); > > Should $rv be bound to $foo or to a copy of $foo? I ask because with > state() and closures, it makes a difference since the value can > change.
Yes, so let's pose an easy, full example with a result we can point at: my $x = 1; my $y := (->{$x}).(); $x++; say $y; Ok, so clearly that prints 1 or 2 (the first person to say it's a junction gets the mean look ;) Some questions I'd add to yours: * We discussed auto-closurizing := statements before, so when does that happen vs. performing the operation and taking the value exactly? * If the above prints 2, then how do you return a value that is a constant "safely"? Do you need to explicitly invoke a cloning operation on it? * How can I talk you out of it? ;-) -- Aaron Sherman <[EMAIL PROTECTED]> Senior Systems Engineer and Toolsmith "It's the sound of a satellite saying, 'get me down!'" -Shriekback