Transparancy
Florian Weimer
fweimer at bfk.de
Thu Jul 8 01:46:45 PDT 2010
* Pavel Minaev:
> Indeed, can you give an example of a popular language which 1) has
> explicit "return", 2) has lambdas, and either 3) does not allow for
> "return" in a lambda, or 4) allows for it, but only in the meaning of
> non-local return?
Perl:
sub foo (@) {
map {return} @_;
print "map did not return non-locally\n";
}
print "calling foo\n";
foo;
print "calling foo\n";
foo 1;
Anonymous subs have proper returns, though. I can ask around if this
is considered good language design.
(I think the consensus with regard to Perl's non-closing behavior of
named nested subprograms is that it's not a good idea at all.)
By the way, all Perl subs have non-local break/continue (which are
called last/next in Perl, in both local and non-local cases):
sub my_break {
last;
}
sub foo {
while (1) {
print "foo\n";
my_break;
}
}
foo;
However, this coding style is discouraged, and the interpreter will
print a warning.
I think Common Lisp has got non-local returns within lexical scope on
downward closures (but Common Lisp was not conceived as a safe
language, so the trade-offs are quite different). Obviously, FORTH
has got some unsafe construct for that purpose, too. I also remember
using something else which had a similar "return from" mechanism, but
I don't recall which language that was (it certainly wasn't something
I would consider popular, perhaps HP-48 User RPL or something like
that).
--
Florian Weimer <fweimer at bfk.de>
BFK edv-consulting GmbH http://www.bfk.de/
Kriegsstraße 100 tel: +49-721-96201-1
D-76133 Karlsruhe fax: +49-721-96201-99
More information about the lambda-dev
mailing list