Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

'temp $x;' with no assignment

0 views
Skip to first unread message

Yuval Kogman

unread,
Mar 27, 2006, 10:26:48 AM3/27/06
to perl6-l...@perl.org
Hi,

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

Jonathan Scott Duff

unread,
Mar 27, 2006, 3:35:52 PM3/27/06
to Yuval Kogman, perl6-l...@perl.org
On Mon, Mar 27, 2006 at 05:26:48PM +0200, Yuval Kogman wrote:
> Hi,
>
> my $x = 5;
> {
> temp $x;
> # is $x 5 or undef?
> }
> # $x is definately 10

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

Yuval Kogman

unread,
Mar 27, 2006, 3:46:02 PM3/27/06
to perl6-l...@perl.org
On Mon, Mar 27, 2006 at 14:35:52 -0600, Jonathan Scott Duff wrote:
> On Mon, Mar 27, 2006 at 05:26:48PM +0200, Yuval Kogman wrote:

> 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.

Jonathan Scott Duff

unread,
Mar 27, 2006, 3:54:05 PM3/27/06
to perl6-l...@perl.org
On Mon, Mar 27, 2006 at 10:46:02PM +0200, Yuval Kogman wrote:
> On Mon, Mar 27, 2006 at 14:35:52 -0600, Jonathan Scott Duff wrote:
> > 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.

Yuval Kogman

unread,
Mar 27, 2006, 4:02:51 PM3/27/06
to perl6-l...@perl.org
On Mon, Mar 27, 2006 at 14:54:05 -0600, Jonathan Scott Duff wrote:

> Make me believe your 90/10 numbers.

http://cpansearch.bulknews.net/ is broken right now... =(

Larry Wall

unread,
Mar 27, 2006, 6:50:13 PM3/27/06
to perl6-l...@perl.org
On Mon, Mar 27, 2006 at 02:54:05PM -0600, Jonathan Scott Duff wrote:

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

Eric

unread,
Apr 6, 2006, 6:13:16 PM4/6/06
to perl6-l...@perl.org

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

Luke Palmer

unread,
Apr 6, 2006, 7:36:56 PM4/6/06
to perl6-l...@perl.org
On 3/27/06, Larry Wall <la...@wall.org> wrote:
> The p5-to-p6 translator will turn
>
> local $x;
>
> into
>
> temp undefine $x;

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

Larry Wall

unread,
Apr 7, 2006, 3:43:26 PM4/7/06
to perl6-l...@perl.org

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

0 new messages