[ZPT] If/else?

Brent M Hendricks brent@valinor.waldenweb.com
Thu, 10 May 2001 09:20:32 -0500


On Wed, May 09, 2001 at 06:15:15PM -0500, Guido van Rossum wrote:
> Evan's latest hacks for this added "(if)" and "(if exists)" to the
> path syntax.  Our latest proposal will remove these again, and add a
> simpler mechanism instead: "x | y | z" will evaluate to the path x if
> it is defined and non-empty, otherwise to y if it is defined and
> non-empty, otherwise to z (which must be defined, but may be empty).

Very nice!  There's a certain elegance to it.

> For those cases where the |-separated sequence doesn't have enough
> expressive power, we propose to fall back on Python expressions
> ("python:<expression>") which are all-powerful, or Python scripts.  In
> order to make testing of paths in Python expressions more convenient,
> we propose adding some simple functions to Python (in the context of
> TALES Python expressions and Zope Python scripts) like
> cond(<expr>, <expr>, <expr>) which serves as a simple if-then-else,

I'm a little unclear on cond().  For example, take 
cond<expA, expB, expC).  Does it transmlate into

if (expA):
   expB
else:
  expC

Or is it more akin to the "x|y|z" construct for path expressions,
returning the first one that is defined and non-empty?


--Brent

-------------------------------------------------------------------------

"The programmer, like the poet, works only slightly removed from pure
 thought-stuff.  He builds his castles in the air, from air, creating
 by exertion of the imagination.  Few media of creation are so
 flexible, so easy to polish and rework, so readily capable of
 realizing grand conceptual structures."
                        -- Frederick Brooks, Jr., The Mythical Man Month