develooper Front page | perl.perl5.porters | Postings from August 2001

new syntax idea: eval "..."o;

From:
David L. Nicol
Date:
August 6, 2001 15:57
Subject:
new syntax idea: eval "..."o;
Message ID:
3B6F1EBB.2BA3F9F4@kasey.umkc.edu

One way to implement rewritability could be to allow a ...o once
switch for eval-string.  The first time through, the string
is expanded and compiled and run, but subsequent times through
it becomes a simple block.

This feature would greatly simplify source code filters, as
they could be arbitrarily deferred.

The advantages 

	eval ${code}o;

has over

	my $FutureCodeRef;
	{
		...
		&{$FutureCodeRef ||= eval "sub {$code}"}
		...
	};

are: 
	Clarity, as it is all in one place instead of requiring
	a named variable, which might get overwritten, and additional
	context blocks

	Faster (no perlop-level conditional, as the eval statement
	would get replaced with the new block.
	

To protect some rewritten code within an eval-as-try block,
we could do this:

	eval { eval qq/$code/o }

For ease of parsing, this might work only with explicit qq/.../
just like the switches on qr/.../.

-- 
                                           David Nicol 816.235.1187
free Dmitry Skylarov




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About