develooper Front page | perl.perl6.language | Postings from August 2001

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

Thread Next
David L. Nicol
August 6, 2001 15:57
new syntax idea: eval "..."o;
Message ID:

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}"}

	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

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