>>> 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
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
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
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.
_
> 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
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
"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))
"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
"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
"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
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
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
"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
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
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
>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
-
"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
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*.
"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
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
20 matches
Mail list logo