Python or Java or maybe PHP?

Mike Meyer mwm at mired.org
Fri Jan 6 20:14:52 CET 2006


Xavier Morel <xavier.morel at masklinn.net> writes:
> Mike Meyer wrote:
>> That doesn't sounds like "hates" to me. More like "doesn't like the
>> baggage."
>>         <mike
> Yet anonymous functions are nice.
>
> Wouldn't it be possible to change the `def` statement to return a
> reference to the function, and allow omitting the function name
> thereby bypassing the default binding (current behavior)?

[...]
>  >>> # Anonymous functions
>  >>> def (*args, **kwargs):
> 		pass
> <function at 0x00FA3830>
>  >>> foo = def(*args, **kwargs): pass

This kind of thing has been proposed a number of times, by a number of
people. Including me.

[examples elided]

> I'm not too sure about the multi line version (and it looks very ugly
> with a non-monospaced font), but:

The multi-line version is actually a killer problem. If you allow
newlines it, you get all kinds of problems with nesting, and the code
gets really ugly. If you don't allow newlines, what you have is barely
more powerfull than the existing lambda, and would tempt people to
write really ugly suites in a single line.

> Pros (I think):
>      * Backwards-compatible (I think, since the new uses of `def` are
>      * currently errors)
>      * Fairly obvious syntax
>      * No `lambda` or `macros` baggage, the new form of def would
>      * merely define an anonymous function instead of a named one.
>      * No new keyword, or structure, or idiom
>      * Existing idioms are merely slightly extended without changing
>      * their current meaning

My version was actually even more backwards compatible - I only
returned the value in the case where you were defining an anonymous
function. Not that that makes any real difference.

> Cons:
>      * May reduce readability when misused, and may be used in Very
>      * Stupid Ways that reduce readability a lot (but then again most
>      * construct may be abused in some way), e.g.:

It's not clear that there are any useful uses that are readable. I had
examples in my proposal, and freely admitted that they were ugly. I
may even have mentioned it in the proposal.

How about some use cases with example usage? That would show us
whether or not there are uses that are both useful and not ugly. Even
if the idea is ultimately rejected, the use cases may generate
different proposals for solving them that are accepted.

          <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list