Python is DOOMED! Again!

Marko Rauhamaa marko at pacujo.net
Sun Feb 8 05:17:04 EST 2015


Ian Kelly <ian.g.kelly at gmail.com>:

> On Sat, Feb 7, 2015 at 5:45 PM, Albert van der Horst
> <albert at spenarnc.xs4all.nl> wrote:
>> x -> x**2
>> instead of
>> lambda x : x**2
>
> Well, I don't think the existing syntax is incompatible with your
> proposal. As it is, the -> token can only appear after the argument
> list of a def statement, so there would be no grammatical ambiguity. I
> do think that such a proposal is unlikely to gain wide support though.

I also don't think Python is in the need of any enhancement in this
area.

>> not
>> def square(x): x**2
>> but
>> square = x->x**2
>
> This would be an anti-pattern. The def statement associates the name
> "square" with the function's __name__ attribute, which is useful for
> debugging and introspection. The proposed assignment statement does
> not.

A good point. However, Guile (Scheme) has some builtin magic:

   > (define (f x) x)
   > (procedure-name f)
   $1 = f
   > (define g (lambda (x) x))
   > (procedure-name g)
   $2 = g
   > (define h g)
   > (procedure-name h)
   $3 = g

>> mult  = x,y ->
>>    result = 0
>>    for i in range(x):
>>       result +=y
>>    return result
>
> I don't like this at all.

The main problem is the missing colon, a cornerstone of Python syntax.

You could have:

   mult  = x,y ->:
      result = 0
      for i in range(x):
         result +=y
      return result

> I read "x -> x**2" as denoting a mapping from a bound variable to an
> expression. A whole function body just feels wrong here.

I don't think syntax like this is in any way wrong. It's just completely
unnecessary given that we have "def".

Some people are trying to make Scheme more Python-like, others are
trying to make Python more Scheme-like. I think you should not dilute
the idiomatic core of a programming language. When in Python, program in
Python, when in Scheme, program in Scheme...


Marko



More information about the Python-list mailing list