Equivalent to (a ? b : c) ?

Rob Hodges s323140 at student.uq.edu.au
Thu Dec 23 14:18:41 EST 1999


Gareth McCaughan <Gareth.McCaughan at pobox.com> writes:

> Rob Hodges wrote:

> > Usually it was used in preference to (if a b c) where using the latter
> > would have required writing (if a (progn b) c) -- that is, b consists
> > of multiple statements.  Of course that is a flow control
> > construction; I've never seen it used the way you write above, which
> > I think could only qualify as intentional obfuscation.  
> 
> I don't think I understand. If B consists of more than one
> statement, how do you do the AND/OR thing without a PROGN?

`and' and `or' will take as many arguments as you like, and keep
evaluating them until there's no point continuing:

(or
 (and something-or-other-p
     non-nil-expr-1
     non-nil-expr-2
     ...)
 nil-expr-1
 nil-expr-2
 ...)

The trick is just not to return nil from any of the statements in B.

> Er, this is getting a bit off-topic...

Yeah, my bad -- sorry for starting this... 

> Interesting. What makes that construction obscure for me
> is mostly the (,,()(((,,),)(,))) stuff, not the "and" and
> "or". I don't mean that the parens and commas do more to
> stop it being easy to sit down and work out than the
> and/or business; I mean that they contribute more to
> the fact that the idiom isn't one the eye just glides
> happily past, even when you know what it does.

To that extent I agree.  But the construct often doesn't need the
tuplification and indexing.  For example when assembling a command
line for a process you're going to spawn, something like

use_r_option and "-r" or ""

is fine without that garbage.  And reasonably elegant, provided the
reader is familiar with it.

> "Idiot" comes from the Greek "idiotes" meaning "layman". I'm not
> sure why "idiotes" means that; perhaps the idea is the contrast
> between the individual layman and the person who's a member of
> whatever institution is in question.

"Layman" has at least the potential for harbouring perjorative
overtones; really it means someone who knows little or nothing --
usually about a particular field of endeavour, but if you've got
someone who knows nothing about anything, I guess that's an idiot.

The message I got off-list said that the Greek root relates to
ownership, and given that, you would expect that "idiot" ought to mean
something like "private person".  Which ties in reasonably well.

Anyway, I think it's time I shut up and desist from diverting the
eyeballs away from the many greater minds here.

-Rob




More information about the Python-list mailing list