Re: lambda and for that matter goto not forgetting sugar

2005-02-11 Thread Richie Hindle

[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=detailatid=305470aid=643835group_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
[EMAIL PROTECTED]

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda and for that matter goto not forgetting sugar

2005-02-11 Thread bearophileHUGS
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

-- 
http://mail.python.org/mailman/listinfo/python-list


lambda and for that matter goto not forgetting sugar

2005-02-10 Thread Philip Smith
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 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda and for that matter goto not forgetting sugar

2005-02-10 Thread Nick Coghlan
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   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: lambda and for that matter goto not forgetting sugar

2005-02-10 Thread John J. Lee
from goto.py ( http://entrian.com/goto/ ):
.# Label: label .x  XXX Computed labels.


:-)


John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lambda and for that matter goto not forgetting sugar

2005-02-10 Thread Carl Banks
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

-- 
http://mail.python.org/mailman/listinfo/python-list