Lambda as declarative idiom (was RE: what is lambda used for in real code?)

Roman Suzi rnd at onego.ru
Tue Jan 4 13:25:56 CET 2005


On Mon, 3 Jan 2005, Steven Bethard wrote:

> Roman Suzi wrote:
> > I wish lambdas will not be deprecated in Python but the key to that is
> > dropping the keyword (lambda). If anybody could think of a better syntax for
> > lambdas _with_ arguments, we could develop PEP 312 further.
>
> Some suggestions from recent lambda threads (I only considered the ones
> that keep lambda as an expression):
>
> ***** Args Before Expression *****
>
> Nick Coghlan: def-to syntax [1]
> (def (a, b, c) to f(a) + o(b) - o(c))
> (def (x) to x * x)

Wow! Is there any wiki-page these could be put on?

By the way, I think to satisfy least-surprise principle, our declarative
idiom must be compatible with type declarations GvR is planning for Python
3.0. This way Python will have ONE style for declarations, be it
type declarations, logical declarations or database-queries, etc.

This means, that there is a need for a LISP's quote, when code is only
written and parsed but may be processed not only by Python interpreter
itself but by any user-made interpreter. For example, type-checker,
cursor.execute, lazy-Python-subinterpreter, DOM-manipulator etc.

I do not know how it could be done syntactically, but it could be done
if thought about long enough.

Lambdas is one of the ways, arguably not the most pleasant one for
a "quote".

Maybe this is too outlandish, but I see lambdas as a "quote" mechanism,
which presents a possibility to postpone (precisely control, delegate)
evaluation. That is, an ovehead for lambda must be much lower but at the
same time visible to the programmer:

 d = a + (lambda x, y: x+ y)(3, 4)

if this expression is to be viewed in hypotetical syntax-highlighting
editor, "(lambda x, y: x+ y)" need to be painted with another color
than the rest of the expression, as it represents defining part of the
expression, not the part which is being evaluated right away.

What if we deprecate ` in it's repr() function and reserve it for
inline lambdas (for Python 3.0, of course):

 d = a + (` x, y: x+y) (3, 4)

Thus, implicit lambdas will be one more symbol, e.g.

(`: None)

instead of

(: None)

What does Guido think? ;)

Sincerely yours, Roman A.Suzi
-- 
 - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -




More information about the Python-list mailing list