On Fri, Jan 03, 2003 at 11:03:22AM -0600, Jeff Epler wrote:
On Fri, Jan 03, 2003 at 09:05:02AM -0500, Bill Bumgarner wrote:
On Friday, Jan 3, 2003, at 00:42 US/Eastern, Gisle Aas wrote:
'anon' sounds like a great name -- unlikely to be used, shorter than 'lambda', and a heck of lot more indicative as to what is going on. 'anon' does not sound that great to me. Anon what? There is lots of anonymous stuff. Arc is going for 'fn'. I would vote for 'sub' :)
Either makes more sense than 'lambda'. I prefer 'anon' because it is a very common abbreviation for 'anonymous' and because it would have reduced the scarring during the learning of lambda calculus in CS so many years ago.
'fn' and 'sub' don't seem to be much differentiated from 'def'. 'fun' would be better than 'fn', though' because that's what lambda functions are...
Of course, you could just extend the syntax of 'def'. the 'funcdef' statement remains as now: funcdef: 'def' NAME parameters ':' suite suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT
but the 'anon_funcdef' expression would be something like anon_funcdef: 'def' parameters ':' suite No new keyword needs to be introduced, and the fact that they have the same name is an even bigger encouragement to identify funcdef and anon_funcdef as working in the same way. (I don't think any of these problems are related specifically to the use of 'def' for both anonymous and named functions, but I'll use my own suggested spelling throughout the following)
Okay, apparently I'm wrong about there being no ambiguity in the grammar. See another subthread where Guido points this out. At least, I'm assuming he's right here. But if we decide that we want anonymous functions that work like expressions, mightn't we decide we want anonymous classes that work like expressions? For instance, instead of def run_server(server_class, socket_class, *args): class Server(server_logic, socket_class): pass Server(*args).run() run_server(DNSServer, UDPSocket) you would write def run_server(server_class, socket_class, *args): (class (server_logic, socket_class): pass)(*args).run() Obviously I've crossed over into the land of the insane here, but I am failing to have the insight to understand why (one-liner) anonymous functions are so useful to many Python programmers, but why a one-liner anonymous class seems like such a frankenstein monster. Of course, right now you could write def run_server(server_class, socket_class, *args): new.classobj("<Server>", (server_class, socket_class), {})(*args).run() but I suspect my first alternative is still preferred. Not being a java user I get the impression that little anonymous classes (or at least classes whose name is not important) are sometimes declared but that this is due to some kind of language wart more than a real desire to do this. Is this executive summary accurate? ("inner classes" or somesuch name?) Jeff