By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

lambda and for that matter goto not forgetting sugar

P: n/a
I've read with interest the continuing debate about 'lambda' and its place
in Python.

Just to say that personally I think its an elegant and useful construct for
many types of programming task (particularly number theory/artificial
intelligence/genetic algorithms)

I can't think why anyone would be proposing to do away with it. Sometimes
an anonymous function is just what you need and surely it just reflects the
python philosophy of everything being an object (in this case a code
object).

Mind you my particular programming interest is algorithmic programming, I
have no idea whether Lambda is of any relevance to eg client server
programming.

For that matter I would find implementing the classical algorithms far
easier if python had 'goto' (I'll wait for the guffaws to subside before
mentioning that no lesser guru than Donald Knuth writes his algorithms that
way - naturally so because it reflects what the machine does at the base
level). Please don't suggest using try/except as an alternative as the
ugliness and inappropriateness of that to achieve a simple 'goto' is utterly
out of keeping with the 'cleanliness' which is Python's most appealing
feature.

(And yes - I do like spaghetti but only to eat, not in my code).

Following on naturally from that last point I would also like to 'deprecate'
the use of the expression 'syntactic sugar' on these pages. All high level
languages (Python included) are nothing but syntactic sugar designed to
conceal the ugliness of what actually gets sent to the CPU to make it all
happen.

On a positive note though - I have found this newsgroup an invaluable aid to
learning Python over the last few weeks and the response to queries has been
as quick as it has been informative.

I've decided I like Python - in fact I think of it more as syntactic maple
syrup than sugar.

Competition: Has anyone found anything you can't do in the language?

regards to all

Phil
Jul 18 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Philip Smith wrote:
I've read with interest the continuing debate about 'lambda' and its place
in Python.

Just to say that personally I think its an elegant and useful construct for
many types of programming task (particularly number theory/artificial
intelligence/genetic algorithms)

I can't think why anyone would be proposing to do away with it. Sometimes
an anonymous function is just what you need and surely it just reflects the
python philosophy of everything being an object (in this case a code
object).
The *concept* is fine, but the current syntax is seriously ugly, and the keyword
used creates false expectations for those familiar with what lambda calculus
actually *is*.

If the lambda syntax were a new proposal to be added to the language now, it
would never be accepted.

Unfortunately, its existence tends to stymie efforts to come up with a
*Pythonic* way of spelling the same idea. The people who want to get rid of
lambda completely think coming up with a new spelling is a waste of time - "Just
define the damn function already!" is their rallying cry. The people who want
real lambda calculus complain that they still can't put statements inside
expressions - they shout "Give me real anonymous functions, not this neutered
junk that restricts me to a single expression!". And, of course, there's always
someone to complain that supporting a new spelling would violate TOOWTDI - "But,
but, we already have def and lambda, why are you trying to come up with yet
another way to create a function?".

Anyway, check out AlternateLambdaSyntax on the python.org Wiki if you haven't
already. For my own part, I'd like a new spelling. Something that is more
stylistically in line with a genexp would be significantly preferable to the
status quo (e.g "(x*x from (x))" aligns better with "(x*x for x in seq)" than
"lambda x: x*x" does).
Following on naturally from that last point I would also like to 'deprecate'
the use of the expression 'syntactic sugar' on these pages. All high level
languages (Python included) are nothing but syntactic sugar designed to
conceal the ugliness of what actually gets sent to the CPU to make it all
happen.


Yup, you're right. But 'syntactic sugar' often isn't used in a negative way -
it's more descriptive than anything. It's any language change that's designed to
make common idioms easier to use.

Cheers,
Nick.
No comment on the goto thing ;)

--
Nick Coghlan | nc******@email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
Jul 18 '05 #2

P: n/a

[Philip]
For that matter I would find implementing the classical algorithms far
easier if python had 'goto'


I can't believe it - first a request for COMEFROM and now one for GOTO,
both on the same day. I should have put http://entrian.com/goto/ under a
commercial license. 8-)

--
Richie Hindle
ri****@entrian.com

Jul 18 '05 #3

P: n/a
On Thu, 10 Feb 2005 15:21:47 +0000, rumours say that Richie Hindle
<ri****@entrian.com> might have written:

[Philip]
For that matter I would find implementing the classical algorithms far
easier if python had 'goto'


I can't believe it - first a request for COMEFROM and now one for GOTO,
both on the same day. I should have put http://entrian.com/goto/ under a
commercial license. 8-)


*Three* requests --check the thread "goto, cls, wait commands". My humourous
suggestion of your module came before I read your own replies to the this and
the other thread.

BTW, my sincere congratulations for what I presume best computer related April's
Fool joke of all time; I love double-bluffs. The worst of all is I've often
referenced your joke when advocating python... :)
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
Jul 18 '05 #4

P: n/a
from goto.py ( http://entrian.com/goto/ ):
.. # Label: "label .x" XXX Computed labels.
:-)
John
Jul 18 '05 #5

P: n/a
Philip Smith wrote:
I've read with interest the continuing debate about 'lambda' and its place in Python.

Just to say that personally I think its an elegant and useful construct for many types of programming task (particularly number theory/artificial intelligence/genetic algorithms)
Well, I've done genetic algorithms in Python, and my implementation
didn't use lambda (other possibly than the occasional and convenient
passing an anonymous function as an argument). If nothing else, my
experience proves GA can be done without lambda.

Most algorithms can be tackled effectively and elegantly by different
programing paradigms. When someone says, "lambda is useful for this,"
often the thruth is "lambda is useful for this _if you are using a
heavily functional style_." Often, someone else could implement the
same algoithm just as effectively without it. For example, me doing
genetic algorithms without it.

Which brings us to my point:

If you're looking for a language that supports a heavily functional
style, Python just isn't it. The functional elements that are in
Python are not there to support heavily functional programming; they
are there to enhance and complement the procedural/iterative style.

Does lambda do that? In my opinion, not much. I never thought it was
crucial, and now that Python has added support more specific (i.e.,
more specifically useful for enhancing procedural code) functional
features, like generator expressions, lambda is less useful than ever.

I'd say it's dispensible and not worth the added complexity.
[snip] For that matter I would find implementing the classical algorithms far easier if python had 'goto' (I'll wait for the guffaws to subside before mentioning that no lesser guru than Donald Knuth writes his algorithms that way - naturally so because it reflects what the machine does at the base level).
I wonder if anyone can come up with a better argument than a certain
isolated retrospectively bad decision Knuth made?

I'm curous whether you have a use case for goto, in Python, that can't
be handled with try...finally or exception handling. We already know
about "the break from multiple loops" one; it's not terribly common to
do that and you can handle it with an exception.

(Ok, I'm actually not curious, cause I'm pretty sure you don't.)
[snip] Competition: Has anyone found anything you can't do in the language?


Mr. Turing is rolling in his grave....
--
CARL BANKS

Jul 18 '05 #6

P: n/a

[Christos]
*Three* requests --check the thread "goto, cls, wait commands".
I saw that too, and was too freaked out to respond.
BTW, my sincere congratulations for what I presume best computer related April's
Fool joke of all time; I love double-bluffs. The worst of all is I've often
referenced your joke when advocating python... :)
Thanks! I think the fact that it was possible at all is a *genuine*
advert for Python's power and flexibility. (Though modifying Python
itself in order to make the joke possible was quite a lot of work:
http://sf.net/tracker/?func=detail&a...&group_id=5470
8-)

[John] from goto.py ( http://entrian.com/goto/ ):
. # Label: "label .x" XXX Computed labels.

:-)


Yay! I've been waiting nearly a year for someone to spot that. 8-)

--
Richie Hindle
ri****@entrian.com

Jul 18 '05 #7

P: n/a
Nick Coghlan wrote:
Anyway, check out AlternateLambdaSyntax on the python.org Wiki


It's an interesting page:
http://www.python.org/moin/AlternateLambdaSyntax
Some days ago I suggested something different: maybe def can become a
function, then it can work as lambda (and still as the old def) too.
Something like:

original :
lambda a, b, c:f(a) + o(b) - o(c)
lambda x: x * x
lambda : x
lambda *a, **k: x.bar(*a, **k)

==>

def(a, b, c): return f(a) + o(b) - o(c)
fun1 = def(x): return x * x
def(): return x
def(*a, **k): return x.bar(*a, **k)

Such def can be used as the lambda inside expressions too.

fun1 = def(a, b, c): return f(a) + o(b) - o(c)
This is the same as the old:
def fun1(a, b, c):
return f(a) + o(b) - o(c)

(That use of "return" in the middle is a little verbose to use it for
functions inside expressions.)

That Ruby syntax at the end of page is cute.
{a,b,c | return f(a) + o(b) - o(c)}
{a,b,c | f(a) + o(b) - o(c)}
def(a, b, c | f(a) + o(b) - o(c) )
fun(a, b, c | f(a) + o(b) - o(c) )
(etc. there are lots of other possibilities).

If def becomes a function like that, then beside this syntax:
fun1 = def(a, b, c): return f(a) + o(b) - o(c)
This other one can be interesting for expressions only:
def(a, b, c | f(a) + o(b) - o(c) )
(Both can be acceptable at the same time).

Bye,
Bearophile

Jul 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.