:= is the thing that implements subroutine arguments. Ask yourself the
same question with:
sub another_routine ($rv) {
...
}
another_routine(some_routine());
I'd expect $rv to be an alias to a copy of $foo's value, 42.
UNLESS some_routine is lvalue (which in this case it is not), in which
case, I'd expect $rv to be an alias to $foo itself
> sub some_rourtine {
> state $foo = 42;
> return $foo++;
> }
rvalue some_rourtine: copy 42
lvalue some_rourtine: error, ++ doesn't return an lvalue
(although prefix ++ probably could).
Juerd
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html
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.
sub some_rourtine {
state $foo = 42;
return $foo++;
}
My apologies if this has been previously discussed or is documented
somewhere. I am still playing catch up. Ok, ok - it's true - I am
looking for a little instant gratification.
Cheers,
Joshua Gatcomb
a.k.a. L~R
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 <a...@ajs.com>
Senior Systems Engineer and Toolsmith
"It's the sound of a satellite saying, 'get me down!'" -Shriekback
Really? Because the default parameter binding is constant reference,
last I checked.
I actually like that answer. It means that you can bind the return
value, but you can't mutate it, unless the function 'is rw'. (And
perhaps you could mark it as 'is copy' and 'is ref', too...)
--
Brent 'Dax' Royal-Gordon <br...@brentdax.com>
Perl and Parrot hacker