[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Omaha.pm] Re: [oma-python] an almost-switch statement
[For the record, thehaas drug me into a Perl discussion on this list. I
tried not to mention Perl at all... -grin-]
On Jun 1, 2004, at 4:19 PM, thehaas@binary.net wrote:
I've used Perl quite a bit. Never used anonymous subroutines because
the syntax is ugly.
It is? From example:
http://www.python.org/doc/current/tut/
node6.html#SECTION006750000000000000000
Python:
$ python
>>> def make_incrementor(n):
... return lambda x: x + n
...
>>> f = make_incrementor(42)
>>> f(0)
42
>>> f(1)
43
I couldn't figure out how to do *exactly* that in Perl. I'm not sure I
understand when you'd want to. You can skip the def step in Perl (I
don't know if you could skip the def step in Python if your wanted to)
thusly:
$ perl -de 1
DB<1> $f = sub { $_[0] + 42 }
DB<2> p &$f(0)
42
DB<3> p &$f(1)
43
OO in Perl is even uglier.
Indeed, it can be. I like Perl OO, but it certainly doesn't have native
cascading public/private attribute inheritance. You can do it (and we
do... a lot...), but it is ugly.
Will Perl 6 ever get out? ;)
At OSCON 2003 Larry Wall and Damian Conway were talking about 2007.
Parrot it coming along, apparently...
j
P.S. Contrary to my last post, Perl has a "Switch" module I didn't know
about:
http://search.cpan.org/~rgarcia/Switch-2.10/Switch.pm
It's distributed in core Perl nowadays, so "use Switch" should be
available by default.