"?:", "a and b or c" or "iif"

Thomas Wouters thomas at xs4all.nl
Wed May 26 07:27:38 EDT 1999


On Tue, May 25, 1999 at 04:35:19PM +0000, Fred L. Drake wrote:

>   Assuming you're emulating "x ? a : b"....
>   This isn't quite it.  Using C's ?:, only one of a or b is evaluated
> when the expression is evaluated.  iif(x, a, b) evaluates both a and
> b.  Sometimes this is acceptable, but not if either a or b has side
> effects or is expensive to evaluate.

[..]

>   Perhaps Python 2 can fix this shortcoming; I'd often like to use
> something equivalent to ?:.

Wait, wait. What's wrong with using 

x and a or b

for constructs similar to '?:' ? It shortcuts like '?:', and you can nest it
to create those hideously unreadable lines C programmers love so much :) (To
be honest, i love them too, in C, when i dont care about readability. I even
used to use them in MOO a lot -- i have two lines of 300+ characters with 7
layers of '?|' (MOO's '?:') constructs, on some old MOO object.)

Earlier someone said it wasn't equivalent -- but why not ? At least it's
more equivalent than an iif() function, isn't it ? Excuse my ignorance if i
missed something obvious.

Regards,
	Thomas.

PS: That reminds me... Are there any stories about who influenced what in
Python and LambdaMOO development ? Timelines ? I'm curious who got what idea
where, as the two languages are ... very similar.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list