Re: Abstract and concrete syntax

2005-06-11 Thread David Baelde
>>> You can do stuff like this: lambda x: x and 2 or 3 >>lambda x: {True:2,False:3}.get(bool(a)) And by the way, I just noticed that this kind of hack is essentially "pushing the control (statement) inside expressions"... People should really admit that statements are expressions and stop twis

Re: Abstract and concrete syntax

2005-06-11 Thread Robert Kern
Terry Reedy wrote: > Beauty is in the eye of the beholder. It seems that relative pythonicity > sometimes is also ;-). Ah, the curse of Pythonicity Relativism! What has society come to that it cannot recognize Absolute Pythonicness and Absolute Perlishness? The measure of Pythonicness was giv

Re: Abstract and concrete syntax

2005-06-10 Thread Kay Schluehr
Terry Reedy wrote: > > lambda x: {True:2,False:3}.get(bool(a)) > > This is limited by the requirement that both branches be computable > regardless of the value of the condition. > > > which is both beautiful and pythonic. > > Beauty is in the eye of the beholder. It seems that relative pythoni

Re: Abstract and concrete syntax

2005-06-10 Thread David Baelde
On Fri, 10 Jun 2005 06:57:19 -0700, Kay Schluehr wrote: >> You can do stuff like this: lambda x: x and 2 or 3 >lambda x: {True:2,False:3}.get(bool(a)) I also think these solutions are just hacks, less efficient, less readable. One shouldn't have to twist her mind to write such an easy idea. _

Re: Abstract and concrete syntax

2005-06-10 Thread David Baelde
> For instance, if assignment were done in an expression, the targets would > have to be quoted to avoid having them evaluated. Or the assignment > expression would have to be a 'special expression' that did not evaluate > all its terms (like setq in some (just older?) lisps). In Python, that

Re: Abstract and concrete syntax

2005-06-10 Thread Benji York
George Sakkis wrote: > Another case I've found handy to use lambdas and expressions instead of > named functions and statements is for simple properties: > > class SomeArray(object): > dimensions = property( > fget = lambda self: (self.x,self.y), > fset = lambda self,(x,y): set

Re: Abstract and concrete syntax

2005-06-10 Thread Terry Reedy
"Kay Schluehr" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Mandus schrieb: >> You can do stuff like this: lambda x: x and 2 or 3 This is limited by the requirement (often met) that bool(true-branch) == True > You can also do this > > lambda x: {True:2,False:3}.get(bool(a))

Re: Abstract and concrete syntax

2005-06-10 Thread George Sakkis
"Kay Schluehr" wrote: > > You can do stuff like this: lambda x: x and 2 or 3 > > You can also do this > >lambda x: {True:2,False:3}.get(bool(a)) > > which is both beautiful and pythonic. > > Kay Beauty is in the eye of the beholder, and the same holds for 'pythonicity'; IMO both are much less

Re: Abstract and concrete syntax

2005-06-10 Thread George Sakkis
"Kay Schluehr" wrote: > > Thu, 09 Jun 2005 03:32:12 +0200 skrev David Baelde: > > [snip] > > > > > > set_callback(obj, > > > lambda x: (if a: > > >2 > > > else: > > >3) > > > > > [snip] > > > > You can do stuff like this: lambda x: x and 2

Re: Abstract and concrete syntax

2005-06-10 Thread George Sakkis
"Mandus" wrote: > Thu, 09 Jun 2005 03:32:12 +0200 skrev David Baelde: > [snip] > > > > set_callback(obj, > > lambda x: (if a: > >2 > > else: > >3) > > > [snip] > > You can do stuff like this: lambda x: x and 2 or 3 > > Of course, you are st

Re: Abstract and concrete syntax

2005-06-10 Thread Kay Schluehr
Mandus schrieb: > As someone who like to do functional style programming, but without a > lot of training in that dept., I miss what you ask for from time to > time. > > I don't want to go to much into this discussion, just comment on a tiny > little bit: > > Thu, 09 Jun 2005 03:32:12 +0200 skrev

Re: Abstract and concrete syntax

2005-06-10 Thread Mandus
As someone who like to do functional style programming, but without a lot of training in that dept., I miss what you ask for from time to time. I don't want to go to much into this discussion, just comment on a tiny little bit: Thu, 09 Jun 2005 03:32:12 +0200 skrev David Baelde: [snip] > > set_ca

Re: Abstract and concrete syntax

2005-06-09 Thread Terry Reedy
"David Baelde" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Well, thanks for the answers. I guess the fact is that python does not > want to be a functional programming language. Correct. Python is a procedural, functional, OO language. > I agree that statements as expressio

Re: Abstract and concrete syntax

2005-06-09 Thread Andrea Griffini
On Thu, 09 Jun 2005 03:32:12 +0200, David Baelde <[EMAIL PROTECTED]> wrote: >I tried python, and do like it. Easy to learn and read This is a key point. How easy is to *read* is considered more important than how easy is to *write*. Re-read the absence of a ternary operator or the limitations of

Re: Abstract and concrete syntax

2005-06-09 Thread David Baelde
Well, thanks for the answers. I guess the fact is that python does not want to be a functional programming language. This concept is quite large, and since there is a proper notion of function with closure, I'd say python is already quite a functional programming language. Even if assignations and

Re: Abstract and concrete syntax

2005-06-09 Thread Michele Simionato
>From a purist perspective the distinction statements/expressions is a mistake. However, if your primary concerns is readability, it makes sense, since it enforces ifs, try.. excepts, etc. to be consistently written for all coders. This definitely helps code review. Michele Simionato -

Re: Abstract and concrete syntax

2005-06-08 Thread George Sakkis
"Greg Ewing" wrote: > > More generally, I think there is no abstract distinction between > > statements and expressions. Everything is an expression, can be evaluated > > to a value. > > That's true in a functional language, but Python is not a > functional language. In imperative programming, of

Re: Abstract and concrete syntax

2005-06-08 Thread Greg Ewing
David Baelde wrote: > Statements are not expressions. > > I feel there are some real problems here. But I can't find anything > absolutely unsolvable. There's no doubt that these problems could be solved in a technical sense, but the real issue is whether the resulting code would be *readable*.

Re: Abstract and concrete syntax

2005-06-08 Thread John Roth
"David Baelde" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Hi, > > I tried python, and do like it. Easy to learn and read (at least for the > commonly used part), has a very large community so great doc and > contributions, and... the design is clean. I come from functional > p

Abstract and concrete syntax

2005-06-08 Thread David Baelde
Hi, I tried python, and do like it. Easy to learn and read (at least for the commonly used part), has a very large community so great doc and contributions, and... the design is clean. I come from functional programming languages, and I do like the proper static binding, the first class functions