Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2005-01-04 15:11:06
Size: 3800
Editor: c-67-165-222-53
Comment: created page from python-list thread "Lambda as declarative idiom"
Revision 3 as of 2005-01-04 16:28:36
Size: 4707
Editor: pcp07851501pcs
Comment:
Deletions are marked like this. Additions are marked like this.
Line 17: Line 17:
Nick Coghlan: def-to syntax [1] Nick Coghlan: def-to syntax [[#a 1]]
Line 26: Line 26:
Nick Coghlan: def-arrow syntax [1] Nick Coghlan: def-arrow syntax [[#a 1]]
Line 35: Line 35:
Alex Martelli: def-as syntax [2] Alex Martelli: def-as syntax [[#b 2]]
Line 44: Line 44:
Dave Benjamin: fun syntax [7] Dave Benjamin: fun syntax [[#g 7]]
Line 53: Line 53:
Roman Suzi: quote-colon syntax [[#i 9]]
{{{#!python
` a, b, c:f(a) + o(b) - o(c)
` x: x * x
` : x
` *a, **k: x.bar(*a, **k)
((` x=x, a=a, k=k: x(*a, **k)) for x, a, k in funcs_and_args_list)
}}}
Line 55: Line 64:
Nick Coghlan: for syntax [6] Nick Coghlan: for syntax [[#f 6]]
Line 64: Line 73:
Robert Brewer: for (no-parens) syntax [3] Robert Brewer: for (no-parens) syntax [[#c 3]]
Line 73: Line 82:
Nick Coghlan: def-from syntax [4] Nick Coghlan: def-from syntax [[#d 4]]
Line 82: Line 91:
Michael Spencer: from-args syntax [5] Michael Spencer: from-args syntax [[#e 5]]
Line 91: Line 100:
Michael Spencer: for-args syntax [5] Michael Spencer: for-args syntax [[#e 5]]
Line 100: Line 109:
Bengt Richter: colon-function-application syntax [9] Bengt Richter: colon-function-application syntax [[#h 8]]
Line 108: Line 117:

=== Real Closures ===

Real closures subsume the functionality of lambda plus allow for multi-line statements.

----

Curly braces for single-line and anonymous def for multi-line (from [[#h 10]], boo [[#h 11]], and this is also very similar to how Ruby does it):
{{{#!python
#single-line (similar to ruby syntax)
{a,b,c | return f(a) + o(b) - o(c)}
{x | return x*x}
{return x}
{*a, **k | return x.bar(*a, **k)}

#multi-line
x = def (a,b,c):
    return f(a) + o(b) - o(c)
}}}
Line 117: Line 146:
 * [[Anchor(h)]] [8] http://mail.python.org/pipermail/python-list/2005-January/258238.html
 * [[Anchor(i)]] [9] http://mail.python.org/pipermail/python-list/2005-January/258578.html
 * [[Anchor(h)]] [8] http://mail.python.org/pipermail/python-list/2005-January/258578.html
 * [[Anchor(i)]] [9] http://mail.python.org/pipermail/python-list/2005-January/258581.html
 * [[Anchor(i)]] [10]
http://mail.python.org/pipermail/python-list/2005-January/258113.html
 * [[Anchor(i)]] [11]
http://boo.codehaus.org/Closures

As it stands, Guido van Rossum has suggested that lambda forms will disappear in ["Python3.0"]. This started a number of threads on comp.lang.python suggesting alternate syntaxes for lambda in the hopes that one of them might be more amenable to GvR's tastes. This pages summarizes these suggestions:

Current Syntax

   1 lambda a, b, c:f(a) + o(b) - o(c)
   2 lambda x: x * x
   3 lambda : x
   4 lambda *a, **k: x.bar(*a, **k)
   5 ((lambda x=x, a=a, k=k: x(*a, **k)) for x, a, k in funcs_and_args_list)

New Syntaxes

Args Before Expression

Nick Coghlan: def-to syntax #a 1

   1 (def (a, b, c) to f(a) + o(b) - o(c))
   2 (def (x) to x * x)
   3 (def () to x)
   4 (def (*a, **k) to x.bar(*a, **k))
   5 ((def (x=x, a=a, k=k) to x(*a, **k)) for x, a, k in funcs_and_args_list)

Nick Coghlan: def-arrow syntax #a 1

   1 (def (a, b, c) -> f(a) + o(b) - o(c))
   2 (def (x) -> x * x)
   3 (def () -> x)
   4 (def (*a, **k) -> x.bar(*a, **k))
   5 ((def (x=x, a=a, k=k) -> x(*a, **k)) for x, a, k in funcs_and_args_list)

Alex Martelli: def-as syntax #b 2

   1 (def (a, b, c) as f(a) + o(b) - o(c))
   2 (def (x) as x * x)
   3 (def () as x)
   4 (def (*a, **k) as x.bar(*a, **k))
   5 ((def (x=x, a=a, k=k) as x(*a, **k)) for x, a, k in funcs_and_args_list)

Dave Benjamin: fun syntax #g 7

   1 (fun(a, b, c): f(a) + o(b) - o(c))
   2 (fun(x): x * x)
   3 (fun(): x)
   4 (fun(*a, **k): x.bar(*a, **k))
   5 ((fun(x=x, a=a, k=k): x(*a, **k)) for x, a, k in funcs_and_args_list)

Roman Suzi: quote-colon syntax #i 9

   1 ` a, b, c:f(a) + o(b) - o(c)
   2 ` x: x * x
   3 ` : x
   4 ` *a, **k: x.bar(*a, **k)
   5 ((` x=x, a=a, k=k: x(*a, **k)) for x, a, k in funcs_and_args_list)

Expression Before Args

Nick Coghlan: for syntax #f 6

   1 (f(a) + o(b) - o(c) for (a, b, c))
   2 (x * x for (x))
   3 (x for ())
   4 (x.bar(*a, **k) for (*a, **k))
   5 ((x(*a, **k) for (x=x, a=a, k=k)) for x, a, k in funcs_and_args_list)

Robert Brewer: for (no-parens) syntax #c 3

   1 (f(a) + o(b) - o(c) for a, b, c)
   2 (x * x for x)
   3 (x for ())
   4 (x.bar(*a, **k) for *a, **k)
   5 ((x(*a, **k) for (x=x, a=a, k=k)) for x, a, k in funcs_and_args_list)

Nick Coghlan: def-from syntax #d 4

   1 (def f(a) + o(b) - o(c) from (a, b, c))
   2 (def x * x from (x))
   3 (def x from ())
   4 (def x.bar(*a, **k) from (*a, **k))
   5 ((def x(*a, **k) from (x=x, a=a, k=k)) for x, a, k in funcs_and_args_list)

Michael Spencer: from-args syntax #e 5

   1 (f(a) + o(b) - o(c) from args(a, b, c))
   2 (x * x from args(x))
   3 (x from args())
   4 (x.bar(*a, **k) from args(*a, **k))
   5 ((x(*a, **k) from args(x=x, a=a, k=k)) for x, a, k in funcs_and_args_list)

Michael Spencer: for-args syntax #e 5

   1 (f(a) + o(b) - o(c) for args(a, b, c))
   2 (x * x for args(x))
   3 (x for args())
   4 (x.bar(*a, **k) for args(*a, **k))
   5 ((x(*a, **k) for args()) for x, a, k in funcs_and_args_list)

Bengt Richter: colon-function-application syntax #h 8

   1 (:f(a) + o(b) - o(c))(a, b, c)
   2 (:x*x)(X)
   3 (:x)()
   4 (:x.bar(*a, **k))(*a, **k)
   5 ((:x(*a, **k))(x=x, a=a, k=k) for x, a, k in funcs_and_args_list)

Real Closures

Real closures subsume the functionality of lambda plus allow for multi-line statements.


Curly braces for single-line and anonymous def for multi-line (from #h 10, boo #h 11, and this is also very similar to how Ruby does it):

   1 #single-line (similar to ruby syntax)
   2 {a,b,c | return f(a) + o(b) - o(c)}
   3 {x | return x*x}
   4 {return x}
   5 {*a, **k | return x.bar(*a, **k)}
   6 
   7 #multi-line
   8 x = def (a,b,c):
   9     return f(a) + o(b) - o(c)

References

http://mail.python.org/pipermail/python-list/2005-January/258113.html

http://boo.codehaus.org/Closures

AlternateLambdaSyntax (last edited 2025-03-16 15:55:44 by elena)

Unable to edit the page? See the FrontPage for instructions.