Michal Wallace wrote:
>
> On Sun, 17 Aug 2003, Benjamin Goldberg wrote:
>
> > Michal Wallace wrote:
> >
> > > Uh-oh. I just went to implement "del x"
> > > and there's no op to remove a variable
> > > from a lexical pad! :)
> >
> > Why would you want to remove a variable from a lexical pad?
> >
> > Surely the "right thing to do" would be to create a new pad (scope),
> > then add your 'x' variable which you plan to 'delete' in the future,
> > then when you want to delete that variable, pop off that pad.
>
> Hmm. Do you mean
>
> if for stmt in block:
> if stmt.type == undef:
> flag_as_going_to_delet(stmt.varname)
>
> So I can create a new pad when it's assigned?
Right. You'd create a new pad just before the "for", and put "stmt"
into it. After the for loop ends, you pop off that pad.
> It can't be a simple pop though, can it?
Why not?
> #!/usr/bin/perl
> $x = "cat";
> $y = "pop $x?";
> undef $x;
> print "x = $x \n";
> print "y = $y \n";
>
> Because here, $x has to be defined before $y, so
> I'd have to delete the -2nd scope. Unless the
> code was smart enough to work out that y is in
> -2 and x is in -1...
These are dynamic variables here; could you give an example of what
you're trying to do with lexicals (my variables)? And remember, undef
doesn't get rid of a variable; it merely stores an undef value into it.
I mean, consider:
#!/usr/bin/perl
use strict;
{ my $x = "cat";
{ my $y = "pop $x";
# $x and $y are both in scope.
undef $x;
# $x and $y are still both in scope.
$x = 2; # no error here!
} # $y goes out of scope.
$x = 42; # ok.
$y = 6*9; # but this is an error.
} # $x goes out of scope now.
$x = 13; # this is an error.
__END__
There's no way, in this program, for $x to be out of scope while $y is
in scope.
> In any case, what does it buy me? it seems like a
> lot of work when there's already a delete_keyed
> op, and leo just made an implementation for pads. :)
>
> I guess in perl it's not bad, since that's the
> whole point of undef, you can just $x = PerlUndef
> it... But in python, this throws a NameError:
>
> x = 1
> del x
> x
>
> So the easiest thing to me is just to translate
> del x as "remove this from the current pad".
Maybe. But, what happens with:
x = 1
y = lambda: x
del x
z = y()
Does/should this also throw a NameError?
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "[EMAIL PROTECTED]
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}