my $x = 5;
{
temp $x;
# is $x 5 or undef?
}
# $x is definately 10
I think it should be 5 inside, because it makes it easy to write
things like:
my $x = 5;
{
temp $x++;
# $x is 6
}
# $x is 5 again
and otherwise pretty much DWIMs, except from a historical
perspective.
--
Yuval Kogman <nothi...@woobling.org>
http://nothingmuch.woobling.org 0xEBD27418
How did $x become 10?!?!? :-)
> I think it should be 5 inside, because it makes it easy to write
> things like:
I think that if C<temp> is the new C<local>, then immediately after the
C<temp $x> line, $x should hold whatever flavor of undef is appropriate.
>
> my $x = 5;
> {
> temp $x++;
> # $x is 6
> }
> # $x is 5 again
>
> and otherwise pretty much DWIMs, except from a historical
> perspective.
Is there some reason we're huffmannizing
my $x = 5;
{
temp $x = $MY::x + 1; # or whatever the proper syntax is
# $x is 6
}
$x = 5;
??
Can you elaborate an example that would show this to be a boon?
-Scott
--
Jonathan Scott Duff
du...@pobox.com
> How did $x become 10?!?!? :-)
GHC has this lovely error: "my brain just exploded"
I think Perl 6 should have a similar runtime warning about how it's
usiong my short term memory for storage ;-)
> I think that if C<temp> is the new C<local>, then immediately after the
> C<temp $x> line, $x should hold whatever flavor of undef is appropriate.
<snip>>
> Is there some reason we're huffmannizing
<snip>
Because 90% of the code that people use local for in perl 5 is for
counting levels and automatically unwrapping them. The other 10% are
for more complex values.
Make me believe your 90/10 numbers.
> Make me believe your 90/10 numbers.
http://cpansearch.bulknews.net/ is broken right now... =(
Doesn't matter what the numbers are, it's the right thing to do.
The default undef hack stems from the days when local() was trying
to fill the role of my() as well. Nowadays temp() should just
mean: "Please arrange to restore yourself to your current value"
and nothing more. (Well, plus the notion that, when applied to a
mutator, the save/restore instruction is passed on to the mutatee to
save itself before the mutation, not after.)
The p5-to-p6 translator will turn
local $x;
into
temp undefine $x;
Larry
In order not do do some strange magic could you jsut do:
temp($x)++;
That seems clear and non magical to me.
Just my 2 cents! ;)
--
--
__________
Eric Hodges
Are you sure that that's not:
undefine temp $x;
It seems to me that the other way would undefine $x and then temporize it.
Luke
Either way works. Remember I just said: "(Well, plus the notion that,
when applied to a mutator, the save/restore instruction is passed
on to the mutatee to save itself before the mutation, not after.)"
And I'd say undefine is definitely a mutator even if you don't call it
with .= syntax. All of these probably end up doing the same thing:
(temp $x).undefine
temp $x.undefine
(temp $x).=undefine
temp $x.=undefine
temp($x .= undefine)
temp($x = undef)
temp $x = undef
Larry