Re: if in expression

2008-08-18 Thread Christian Schmidt
On 18 Aug., 10:22, John Machin <[EMAIL PROTECTED]> wrote: > On Aug 18, 5:46 pm, [EMAIL PROTECTED] wrote: > > I'm using IronPython to evaluate expressions, so I can't use the > > return statement but have to say it in an one-liner. > > By "evaluate expressions", do you mean using the eval built-in >

Re: if in expression

2008-08-18 Thread Hrvoje Niksic
Fredrik Lundh <[EMAIL PROTECTED]> writes: > Hrvoje Niksic wrote: > >>> If you want lazy evaluation, you can use lambdas: >>> >>> iif(cond, lambda: then, lambda: else_)() >> >> Your code uses "iif" and attempts to evaluate a tuple; could you post >> an example that works? >> >> I ask because it's n

Re: if in expression

2008-08-18 Thread Fredrik Lundh
Hrvoje Niksic wrote: If you want lazy evaluation, you can use lambdas: iif(cond, lambda: then, lambda: else_)() Your code uses "iif" and attempts to evaluate a tuple; could you post an example that works? I ask because it's not clear what you mean by lazy evaluation in this context. The ter

Re: if in expression

2008-08-18 Thread Diez B. Roggisch
Hrvoje Niksic schrieb: "Diez B. Roggisch" <[EMAIL PROTECTED]> writes: Since python 2.5, it is if else If you want lazy evaluation, you can use lambdas: iif(cond, lambda: then, lambda: else_)() Your code uses "iif" and attempts to evaluate a tuple; could you post an example that works?

Re: if in expression

2008-08-18 Thread Hrvoje Niksic
"Diez B. Roggisch" <[EMAIL PROTECTED]> writes: > Since python 2.5, it is > > if else > > If you want lazy evaluation, you can use lambdas: > > iif(cond, lambda: then, lambda: else_)() Your code uses "iif" and attempts to evaluate a tuple; could you post an example that works? I ask because it

Re: if in expression

2008-08-18 Thread Fredrik Lundh
John Machin wrote: There is an even more unreadable hack (due to Tim Peters IIRC) that avoides the false-then problem: (cond and [then_value] or [else_value])[0] The correct attribution is "due to Tim Peters (who wishes it was Steve Majewski)." -- http://mail.python.org/mailman/listinfo/

Re: if in expression

2008-08-18 Thread John Machin
On Aug 18, 5:46 pm, [EMAIL PROTECTED] wrote: > Hi, > I'm using IronPython to evaluate expressions, so I can't use the > return statement but have to say it in an one-liner. By "evaluate expressions", do you mean using the eval built-in function? If so, find the recent thread addressing this topic;

Re: if in expression

2008-08-18 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: Hi, I'm using IronPython to evaluate expressions, so I can't use the return statement but have to say it in an one-liner. Using C/C++ I could use "cond ? then : else" to have an expression-if, but in Python there's no such operator. The "cond and then or else"-trick onl