[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Syntax for one-line "nonymous" functions in "declaration style"

On 27/03/19 09:21, Alexey Muranov wrote:
> Whey you need a simple function in Python, there is a choice between a
> normal function declaration and an assignment of a anonymous function
> (defined by a lambda-expression) to a variable:
> ?? def f(x): return x*x
> or
> ?? f = lambda x: x*x
> It would be however more convenient to be able to write instead just
> ?? f(x) = x*x 

I have mixed feelings about this. I think anonymous functions only have a
place as arguments to a function. So f(x) = x * x, doesn't look like an 
anonymous function but just an other way to have a named fuction. (as
others have already pointed out)

If we really want an alternative for the lambda expresion, I would go
for the following.

f = x -> x*x (or maybe we could have the ? instead of lambda)

If we want haskell like patterns for defining functions I would go
for the following:

fac(0) -> 1
fac(n) -> n * fac(n - 1)

Which seems incompatible with the proposal for an alternative lambda. 

Antoon Pardon.