Steven D'Aprano <ste...@remove.this.cybersource.com.au> 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 ' sub AUTOLOAD { my $name = our $AUTOLOAD; *$AUTOLOAD = sub { local $" = ", "; print "$name(@_)\n" }; goto &$AUTOLOAD; } foo(40); bar("hello", "world!"); baz(foo(10));' output: main::foo(40) main::bar(hello, world!) main::foo(10) main::baz(1) NB: calling foo 10 returns 1 (return value of print). -- John Bokma j3b Hacking & Hiking in Mexico - http://johnbokma.com/ http://castleamber.com/ - Perl & Python Development -- http://mail.python.org/mailman/listinfo/python-list