Re: [Python-Dev] Use an empty def as a lambda

2013-09-21 Thread Steven D'Aprano
Guys, this thread is not Python-Dev territory. It should have gone to
Python-Ideas. I repeat what I posted two days ago:

Proposals for changes to syntax and functionality are normally 
expected to gather feedback on python-ideas before coming to 
python-dev for final approval or rejection.

https://mail.python.org/mailman/listinfo/python-ideas

http://docs.python.org/devguide/communication.html


Please drop the discussion here.


-- 
Steven
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Use an empty def as a lambda

2013-09-21 Thread Westley Martínez
> -Original Message-
> From: Python-Dev [mailto:python-dev-bounces+anikom15=gmail@python.org] On
> Behalf Of Ben Finney
> Sent: Saturday, September 21, 2013 12:56 PM
> To: python-dev@python.org
> Subject: Re: [Python-Dev] Use an empty def as a lambda
> 
> Westley Martínez  writes:
> 
> > My reasoning is that we use class to make classes, lambda to make
> > lambda functions, and def to make--well not defs--functions, which
> > doesn't really make sense to me.
> 
> Your reasoning is flawed. There is no such thing in Python as a “lambda
> function”.
> 
> Python has functions. It doesn't matter whether you use a ‘lambda’ or
> ‘def’ statement to create it, there's no resulting difference in the
> type of the object. It is a function.
> 
> So: you make a class with a ‘class’ statement; you make a function using
> either a ‘def’ statement or a ‘lambda’ expression. There is no third
> type of object being discussed here.

This is true.  The final object the Python creates is, to my knowledge,
the same regardless of whether it uses define or lambda.  But it's
irrelevant if it's the same or not, since one could argue that every-
thing is going to end up as a series of 0s and 1s.  In that sense a
function is nothing more than a glorified integer.  Lambda function is
just a term, like method or procedure instead function, although it is
certainly more specific in the sense that it is anonymous.  In my list I
was citing general concepts, not specific Python objects.

class is obvious, lambda is obvious, def is not as obvious, though
certainly more obvious than C-style declarations.  If lambda should
change I think anon or expr would be more suitable, or even func (so
long as def not become func).

___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Use an empty def as a lambda

2013-09-21 Thread Ben Finney
Westley Martínez  writes:

> My reasoning is that we use class to make classes, lambda to make
> lambda functions, and def to make--well not defs--functions, which
> doesn't really make sense to me.

Your reasoning is flawed. There is no such thing in Python as a “lambda
function”.

Python has functions. It doesn't matter whether you use a ‘lambda’ or
‘def’ statement to create it, there's no resulting difference in the
type of the object. It is a function.

So: you make a class with a ‘class’ statement; you make a function using
either a ‘def’ statement or a ‘lambda’ expression. There is no third
type of object being discussed here.

-- 
 \ “Faith may be defined briefly as an illogical belief in the |
  `\  occurrence of the improbable.” —Henry L. Mencken |
_o__)  |
Ben Finney

___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Use an empty def as a lambda

2013-09-21 Thread Westley Martínez
When I say Python 4000, I don't actually mean Python 4.x, I mean the
next backwards-incompatible revision to Python (if it comes to pass).
My reasoning is that we use class to make classes, lambda to make
lambda functions, and def to make--well not defs--functions, which
doesn't really make sense to me.

Changing lambda to def would break compatibility as well and restrict
the grammar further.  In addition, it provides little foreseeable
benefit since the term def has no real meaning outside of Python,
whilst lambda has a clearly defined meaning.  Had the original C pro-
grammers chosen def in lieu of typedef or #def in lieu of #define, I
doubt that def would have been chosen as the keyword for functions in
Python.

> -Original Message-
> From: Ryan [mailto:rym...@gmail.com]
> Sent: Saturday, September 21, 2013 10:55 AM
> To: Westley Martínez; 'Ben Gift'; python-dev@python.org
> Subject: Re: [Python-Dev] Use an empty def as a lambda
> 
> Change def to func? That's the worst idea I've heard yet. Def is already
> there; why break all existing code just for a word?
> 
> 
> "Westley Martínez"  wrote:
> 
>   'def' is no more ambiguous than 'lambda', and is in fact more ambiguous,
>   for 'def' doesn't lend itself to anything other than the word define,
>   whilst 'lambda' can only mean lambda function.  Calling def explicit is
>   silly.  It only makes sense because def arbitrarily means a function in
>   Python (I'm proposing def become func or proc in Python 4000).
> 
>   To call lambda too 'computer sciencey' is equally ridiculous, for pro-
>   gramming is a key spawn of computer science.  A programmer needs to have
>   some knowledge of computer science to program, just like a physicist
>   needs knowledge of calculus to understand mechanics.
> 
> 
>   -Original Message-
>   From: Python-Dev [mailto:python-dev-
> bounces+anikom15=gmail....@python.org] On
>           Behalf Of Ben Gift
>   Sent: Thursday, September 19, 2013 1:54 PM
>   To: python-dev@python.org
>   Subject: [Python-Dev] Use an empty def as a lambda
> 
>   I think the lambda keyword is difficult to understand for many
> people. It
>   would be more pythonic to use an empty def call instead.
> 
> 
>   For instance this:
> 
> 
>   words.sort(key = lambda x: x[2])
> 
> 
>   could look like this:
> 
>   words.sort(key = def (x): x[2])
> 
> 
>   It's obvious and explicit that we're creating an unnamed,
> anonymous function
>   this way.
> 
> 
> 
> 
> 
> 
>   Python-Dev mailing list
>   Python-Dev@python.org
>   https://mail.python.org/mailman/listinfo/python-dev
>   Unsubscribe: https://mail.python.org/mailman/options/python-
> dev/rymg19%40gmail.com
> 
> 
> --
> Sent from my Android phone with K-9 Mail. Please excuse my brevity.

___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Use an empty def as a lambda

2013-09-21 Thread R. David Murray
On Sat, 21 Sep 2013 12:55:20 -0500, Ryan  wrote:
> "Westley Martínez"  wrote:
> >'def' is no more ambiguous than 'lambda', and is in fact more
> >ambiguous,
> >for 'def' doesn't lend itself to anything other than the word define,
> >whilst 'lambda' can only mean lambda function.  Calling def explicit is
> >silly.  It only makes sense because def arbitrarily means a function in
> >Python (I'm proposing def become func or proc in Python 4000).
>
> Change def to func? That's the worst idea I've heard yet. Def is
> already there; why break all existing code just for a word?

Note that whatever happens with Python4, breaking of backward
compatibility (by anything other than the deletion of cruft) is very
unlikely to be part of it.

--David
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Use an empty def as a lambda

2013-09-21 Thread Ryan
Change def to func? That's the worst idea I've heard yet. Def is already there; 
why break all existing code just for a word?

"Westley Martínez"  wrote:

>'def' is no more ambiguous than 'lambda', and is in fact more
>ambiguous,
>for 'def' doesn't lend itself to anything other than the word define,
>whilst 'lambda' can only mean lambda function.  Calling def explicit is
>silly.  It only makes sense because def arbitrarily means a function in
>Python (I'm proposing def become func or proc in Python 4000).
>
>To call lambda too 'computer sciencey' is equally ridiculous, for pro-
>gramming is a key spawn of computer science.  A programmer needs to
>have
>some knowledge of computer science to program, just like a physicist
>needs knowledge of calculus to understand mechanics.
>
>> -Original Message-
>> From: Python-Dev
>[mailto:python-dev-bounces+anikom15=gmail....@python.org] On
>> Behalf Of Ben Gift
>> Sent: Thursday, September 19, 2013 1:54 PM
>> To: python-dev@python.org
>> Subject: [Python-Dev] Use an empty def as a lambda
>> 
>> I think the lambda keyword is difficult to understand for many
>people. It
>> would be more pythonic to use an empty def call instead.
>> 
>> 
>> For instance this:
>> 
>> 
>> words.sort(key = lambda x: x[2])
>> 
>> 
>> could look like this:
>> 
>> words.sort(key = def (x): x[2])
>> 
>> 
>> It's obvious and explicit that we're creating an unnamed, anonymous
>function
>> this way.
>
>
>___
>Python-Dev mailing list
>Python-Dev@python.org
>https://mail.python.org/mailman/listinfo/python-dev
>Unsubscribe:
>https://mail.python.org/mailman/options/python-dev/rymg19%40gmail.com

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Use an empty def as a lambda

2013-09-20 Thread Lennart Regebro
On Thu, Sep 19, 2013 at 10:54 PM, Ben Gift  wrote:
> I think the lambda keyword is difficult to understand for many people. It
> would be more pythonic to use an empty def call instead.

I agree, but that ship has sailed, at least until the time when Python
2 is dead. I don't want these kinds of syntax changes for a *long*
time now, personally.

//Lennart
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Use an empty def as a lambda

2013-09-20 Thread Westley Martínez
'def' is no more ambiguous than 'lambda', and is in fact more ambiguous,
for 'def' doesn't lend itself to anything other than the word define,
whilst 'lambda' can only mean lambda function.  Calling def explicit is
silly.  It only makes sense because def arbitrarily means a function in
Python (I'm proposing def become func or proc in Python 4000).

To call lambda too 'computer sciencey' is equally ridiculous, for pro-
gramming is a key spawn of computer science.  A programmer needs to have
some knowledge of computer science to program, just like a physicist
needs knowledge of calculus to understand mechanics.

> -Original Message-
> From: Python-Dev [mailto:python-dev-bounces+anikom15=gmail@python.org] On
> Behalf Of Ben Gift
> Sent: Thursday, September 19, 2013 1:54 PM
> To: python-dev@python.org
> Subject: [Python-Dev] Use an empty def as a lambda
> 
> I think the lambda keyword is difficult to understand for many people. It
> would be more pythonic to use an empty def call instead.
> 
> 
> For instance this:
> 
> 
> words.sort(key = lambda x: x[2])
> 
> 
> could look like this:
> 
> words.sort(key = def (x): x[2])
> 
> 
> It's obvious and explicit that we're creating an unnamed, anonymous function
> this way.


___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Use an empty def as a lambda

2013-09-19 Thread Steven D'Aprano
On Thu, Sep 19, 2013 at 01:54:08PM -0700, Ben Gift wrote:
> I think the lambda keyword is difficult to understand for many people. It
> would be more pythonic to use an empty def call instead.

Hi Ben, and welcome! Is this your first post? I'm afraid I don't 
recognise your name.

I think this discussion belongs on the python-ideas mailing list rather 
than here. Proposals for changes to syntax and functionality are 
normally expected to gather feedback on python-ideas before coming to 
python-dev for final approval or rejection.

https://mail.python.org/mailman/listinfo/python-ideas

http://docs.python.org/devguide/communication.html



-- 
Steven
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Use an empty def as a lambda

2013-09-19 Thread Ryan Gonzalez
Nice idea, BUT...

Not sure how a parser addition that supports it would go. Imagine this: if
you did a one-line function:

def test(x): print(x)

Python could interpret it two ways:

`def` `name` `lparen` `name` `rparen` `colon`...

OR, it could see it as a lambda-like thingamajig and throw a syntax error.
And, if someone accidentally wrote:

def (x): print(x)

Python should throw a syntax error. But it won't. And it'll take the person
a tad bit to realize he forgot the function name. Whoops.

And, it just would be odd in general.


On Thu, Sep 19, 2013 at 3:54 PM, Ben Gift  wrote:

> I think the lambda keyword is difficult to understand for many people. It
> would be more pythonic to use an empty def call instead.
>
> For instance this:
>
> words.sort(key = lambda x: x[2])
>
> could look like this:
>
> words.sort(key = def (x): x[2])
>
> It's obvious and explicit that we're creating an unnamed, anonymous
> function this way.
>
> ___
> Python-Dev mailing list
> Python-Dev@python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/rymg19%40gmail.com
>
>


-- 
Ryan
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Use an empty def as a lambda

2013-09-19 Thread Alexander Belopolsky
On Thu, Sep 19, 2013 at 4:54 PM, Ben Gift  wrote:

> It would be more pythonic to use an empty def call instead.


No, it won't.  Python draws a very strong distinction between expressions
and statements.  This line has been blurred somewhat with the advent of
 comprehensions and the if-else expression, but it would still require more
benefit than three characters in a keyword saving to allow def use in both
statements and expressions.

The following, for example, does not look pythonic at all:

*def* transform(*seq*, *func*=*def*(*x*):*x*):
  ...

(Note that I attempted to emulate syntax highlighting to make my point.)
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Use an empty def as a lambda

2013-09-19 Thread Joe Pinsonault
I think it's a great idea personally. It's explicit and obvious. "lamda" is
too computer sciencey
On Sep 19, 2013 1:55 PM, "Ben Gift"  wrote:

> I think the lambda keyword is difficult to understand for many people. It
> would be more pythonic to use an empty def call instead.
>
> For instance this:
>
> words.sort(key = lambda x: x[2])
>
> could look like this:
>
> words.sort(key = def (x): x[2])
>
> It's obvious and explicit that we're creating an unnamed, anonymous
> function this way.
>
> ___
> Python-Dev mailing list
> Python-Dev@python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/joe.pinsonault%40gmail.com
>
>
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Use an empty def as a lambda

2013-09-19 Thread Ben Gift
I think the lambda keyword is difficult to understand for many people. It
would be more pythonic to use an empty def call instead.

For instance this:

words.sort(key = lambda x: x[2])

could look like this:

words.sort(key = def (x): x[2])

It's obvious and explicit that we're creating an unnamed, anonymous
function this way.
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Use an empty def as a lambda

2013-09-19 Thread Nick Coghlan
On 20 Sep 2013 07:04, "Joe Pinsonault"  wrote:
>
> I think it's a great idea personally. It's explicit and obvious. "lamda"
is too computer sciencey

This suggestion has been made many times, occasionally with the associated
"must be contained in parentheses when used as an expression" caveat that
is needed to avoid making the language grammar ambiguous at the statement
level.

It mainly runs afoul of two problems:

- reusing the same keyword would make the additional syntactic restrictions
of the expression form even more confusing.
- Guido doesn't particularly like the notion of functions-as-expressions in
the first place (which is why lambda was on thin ice when Python 3 was
being designed), so doesn't actually mind the fact that people avoid using
them because they don't like the keyword.

Cheers,
Nick.

>
> On Sep 19, 2013 1:55 PM, "Ben Gift"  wrote:
>>
>> I think the lambda keyword is difficult to understand for many people.
It would be more pythonic to use an empty def call instead.
>>
>> For instance this:
>>
>> words.sort(key = lambda x: x[2])
>>
>> could look like this:
>>
>> words.sort(key = def (x): x[2])
>>
>> It's obvious and explicit that we're creating an unnamed, anonymous
function this way.
>>
>> ___
>> Python-Dev mailing list
>> Python-Dev@python.org
>> https://mail.python.org/mailman/listinfo/python-dev
>> Unsubscribe:
https://mail.python.org/mailman/options/python-dev/joe.pinsonault%40gmail.com
>>
>
> ___
> Python-Dev mailing list
> Python-Dev@python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
>
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Use an empty def as a lambda

2013-09-19 Thread Xavier Morel
On 2013-09-19, at 23:17 , Nick Coghlan wrote:

> On 20 Sep 2013 07:04, "Joe Pinsonault"  wrote:
>> 
>> I think it's a great idea personally. It's explicit and obvious. "lamda"
> is too computer sciencey
> 
> This suggestion has been made many times, occasionally with the associated
> "must be contained in parentheses when used as an expression" caveat that
> is needed to avoid making the language grammar ambiguous at the statement
> level.

Examples of some of these times:

https://wiki.python.org/moin/AlternateLambdaSyntax
https://mail.python.org/pipermail/python-dev/2006-February/060415.html
https://mail.python.org/pipermail/python-dev/2006-February/thread.html#60415

Unless significant new insight is developed or Guido has picked the
functional bug at dropbox, merely suggesting a name change from lambda
to def (which has already been suggested in the past) probably isn't
going to cut it.
___
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com