lambdak: multi-line lambda implementation in native Python

Roy Smith roy at
Sat Jan 17 17:56:48 CET 2015

In article <54ba39e0$0$13008$c3e8da3$5496439d at>,
 Steven D'Aprano <steve+comp.lang.python at> wrote:

> Every time I think I would like to learn a new language, I quite quickly run
> into some obvious feature that Python has but the newer language lacks, and
> I think "bugger this for a game of soldiers" and abandon it.

Wow.  Another wonderful English phrase to add to my vocabulary.  That's 
up there with Bob's your uncle :-)

> Ah, wait, I forgot Ruby's brilliant "feature" that whitespace *between*
> expressions is significant:
> [steve at ando ~]$ cat ~/coding/ruby/ws-example.rb
> #!/usr/bin/ruby
> def a(x=4)
>     x+2
> end
> b = 1
> print "a + b => ", (a + b), "\n"
> print "a+b   => ", (a+b), "\n"
> print "a+ b  => ", (a+ b), "\n"
> print "a +b  => ", (a +b), "\n"
> [steve at ando ~]$ ruby ~/coding/ruby/ws-example.rb
> a + b => 7
> a+b   => 7
> a+ b  => 7
> a +b  => 3
> A shiny new penny for any non-Ruby coder who can explain that!

The last time I looked at Ruby was when it was brand new.  I bought the 
original pickaxe book and read it on a plane trip.  It looked pretty 
cool at the time, but I never really got into it.  So I think I qualify.

Anyway, I'm going to guess from the above examples, that uttering a name 
means, "If the referent is callable, call it, if not, get its value".  
This is the same, for example, as django's template language.  Or, kind 
of like Python's properties.  So

(a + b)

means "Call a(), and add the value of b to that".  I'm going to further 
guess that

def a(x=4)

means a() takes an optional argument, with a default value of 4, just 
like in Python.  So


returns 6, i.e. 4 + 2.  I'm going to further guess that

(a +b)

is parsed as "call a, passing +b as an argument", and the "+" is taken 
as a unary prefix.

I want my penny.

This is not the only example of significant whitespace in programming 

Old-style C/C++ allowed either += or =+ for the increment operator.  
This led to parsing ambiguity for things like a=+b, where (IIRC), "a = 
+b" was parsed as an assignment and unary +, and "a =+ b" was parsed as 
an increment.  Eventually, the syntax was changed to make += the only 
legal way to write increment.

There was also the problem with nested template operators in C++, where 
"Foo<T1<T2>>" was mis-parsed, and you had to write it as "Foo <T1 <T2> 
>" (or something like that) to get it to parse right.

More information about the Python-list mailing list