Interesting talk on Python vs. Ruby and how he would like Python to have just a bit more syntactic flexibility.

John Bokma john at
Thu Feb 18 03:23:19 CET 2010

Steven D'Aprano <steven at> writes:

> On Wed, 17 Feb 2010 12:39:30 -0600, John Bokma wrote:

>> If it was Perl [1], I doubt it. Because line numbers are reported, and
>> if that doesn't help you, you can annotate anonymous functions with a
>> nick name using
>> local *__ANON__ = 'nice name';
> [...]
>> As you can see, and a line number is generated, and the nice name is
>> shown.
> Given that it has a nice name, what makes it an anonymous function?

You can't do 

nice name();

It just changes what perl reports.

> If this is the case, then your answer to "anonymous functions are a
> PITA" 

I don't think anon functions are in general a
PITA. Like with most things, (I) use them in moderation.

> is "don't use anonymous functions", which exactly the same answer we'd 
> give here in Python land. The only difference is that Perl provides two 
> ways of making a named function, and Python only one[1].

Note that the local trick doesn't create a named function. There are
other ways of course to create named functions in Perl, e.g.

perl -e '*foo=sub { print "hello, world\n" }; foo();'

Which can be fun:

perl -e '
    my $name = our $AUTOLOAD;
    *$AUTOLOAD = sub { local $" = ", "; print "$name(@_)\n" };
    goto &$AUTOLOAD;
bar("hello", "world!");


main::bar(hello, world!)

NB: calling foo 10 returns 1 (return value of print).

John Bokma                                                               j3b

Hacking & Hiking in Mexico - - Perl & Python Development

More information about the Python-list mailing list