473,322 Members | 1,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

lambda and for that matter goto not forgetting sugar

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
7 1551
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

[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
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
from goto.py ( http://entrian.com/goto/ ):
.. # Label: "label .x" XXX Computed labels.
:-)
John
Jul 18 '05 #5
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

[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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

63
by: Stephen Thorne | last post by:
Hi guys, I'm a little worried about the expected disappearance of lambda in python3000. I've had my brain badly broken by functional programming in the past, and I would hate to see things...
36
by: Michael | last post by:
Hi, I know I know its notoriously bad! I don't want to use it. I was wondering, does it still exist? If it does, I really don't understand how!? like what happens if you just goto halfway through...
30
by: Mike Meyer | last post by:
I know, lambda bashing (and defending) in the group is one of the most popular ways to avoid writing code. However, while staring at some Oz code, I noticed a feature that would seem to make both...
267
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at...
5
by: Maxim Veksler | last post by:
Hello, I'm new on this list and in python. It seems python has some interesting concept of "ad hoc" function which I'm trying to understand without much success. Take the following code for...
67
by: Rui Maciel | last post by:
I've been delving into finite state machines and at this time it seems that the best way to implement them is through an intense use of the goto statement. Yet, everyone plus their granmother is...
15
by: Matt | last post by:
Hi There, Can anyone explain me the real advantages of (other than syntax) lambda expressions over anonymous delegates? advantage for one over the other. delegate int F(int a); F fLambda = a...
15
by: K Viltersten | last post by:
I've got a hint from a gentleman here to use the following syntax. public static FileInfo GetFilesRegExp(this DirectoryInfo di, string pat) { Regex re = new Regex(pat); return Array.FindAll(...
20
by: raylopez99 | last post by:
Took a look at all the fuss about "lambda expressions" from Jon Skeet's excellent book "C# in Depth". Jon has an example, reproduced below (excerpt) on lambda expressions. My n00b take: it's...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.