Front page | perl.perl5.porters |
Postings from November 1999
Re: making pragmas?
Thread Previous
|
Thread Next
From:
Larry Wall
Date:
November 19, 1999 17:14
Subject:
Re: making pragmas?
Message ID:
199911200110.RAA24590@kiev.wall.org
japhy@pobox.com writes:
: Is there something internally special about pragmas? Specifically, is
: there any reason we can't make our own?
It depends, of course, on what you mean by "we", and "our own".
Anybody can hack Perl however they want. However, if you don't want
your private changes to collide with the future of the language itself,
then it's good to make the pragma public property (or at least reserve
the name), in which case it's likely to have to go through a discussion
phase before "we" becomes "us". Or something like that...
In other words, it's basically the same as for ordinary modules that might
someday go onto CPAN, only more so. But I've always said that any given
module can warp the language any way it jolly well pleases, as long as
it is explicitly declared up at the top. The archtypical case being
use Python;
def fib(n): # return Fibonacci series up to n
result = []
a, b = 0, 1
while b < n:
result.append(b)
a, b = b, a+b
return result
which would presumably compile down to something like
sub fib {
my ($n) = @_;
my $result = [];
my ($a, $b) = (0, 1);
while ($b < $n) {
push @$result, $b;
($a, $b) = ($b, $a+$b);
}
return $result;
}
(leaving aside technical difficulties such as the fact that Python
doesn't actually have lexically scoped variables.)
I suppose an argument could be made that if we installed this into
standard Perl, it should be a pragma,
use python;
especially since
use Python;
might merely embed a Python interpreter into Perl, which is not as much fun.
Larry
Thread Previous
|
Thread Next