develooper Front page | perl.perl5.porters | Postings from March 2003

Re: PROPOSAL: my $x if $false; and lexical initialisation

Thread Previous | Thread Next
Dave Mitchell
March 1, 2003 11:45
Re: PROPOSAL: my $x if $false; and lexical initialisation
Message ID:
On Sat, Mar 01, 2003 at 11:19:52AM -0800, Gurusamy Sarathy wrote:
> I'm not sure nextstate is the best place for this.  Since this is
> only needed once per scope, checking for it once-per-statement
> seems like wasted cycles.
> Why not do it in the OP_LEAVE* ops?  Or perhaps even introduce
> a new OP_LEAVEMY that only fires if there are lexicals that
> need to be finalized in that scope.


A problem with an OP_LEAVEMY is that it often won't get called, eg

    sub f {
	my $x = Obj->new();
	return if ...;
	die if ....;

Is there a way of ensuring that the op is always called no matter how the
scope is unwound?

Another objection to an OP_LEAVEMY is that it might do many unnecessary
finalisations, eg

    while (<>) {
	next unless /..../;
	my ($a, $b, $c, ....);

Here the lexes would be finialised each time round the loop, whereas
currently that's skipped. That's one reason for attaching the finalisation
to each nextstate (or rather, pushing a finalisation on the savestack
for each nextstate).

Another option would be to insert an OP_STARTMY after each nextstate
that preceeeded a my declaration ???

Any [programming] language that doesn't occasionally surprise the
novice will pay for it by continually surprising the expert.
 - Larry Wall

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About