[ZPT] Using variables in path expressions

Brent Hendricks brentmh@ece.rice.edu
Fri, 8 Jun 2001 08:19:04 -0500


On Fri, Jun 08, 2001 at 12:04:04AM -0400, Evan Simpson wrote:
> From: "Brent M Hendricks" <brent@valinor.waldenweb.com>
> > Hmm.  Is there a technical reason why it uses a different syntax here?
> > In the interest of consistency, I'd think we would want to use ${} here
> > too.
> 
> There's a subtle difference between string interpolation and path
> interpolation that we wanted to highlight with differing syntax.  In path
> interpolation, you split the path at the slashes, then replace '?x'
> elements.  Thus, "here/?name" is always a two-element path and will fail to
> resolve if 'name' is 'a/b', even if "here/a/b" exists. To resolve, 'name'
> would need to be ['a', 'b']. Also, the element must start with the question
> mark in order to be interpolated, so "a/x?b/c" will not cause path
> interpolation.

Ahh, I get it.  The semantics are sufficiently different to warrant a
new notation.  Using ${}, people would expect it to behave the same
way.

> > And since I'm already nagging you about notation (<grin>), I might as
> > well ask: How hard would it be to allow paths embedded in paths?  I
> > would think you could just pass the expression through the "string:"
> > processor first to expand the variables and then pass the resultant
> > string into the "path:" processor.
> 
> As a matter of fact, you can do just that in a Python expression, at least
> three ways:
> 
> python:path(string('a/${x/y}/c'))
> python:path('a/%s/c' % path('x/y'))
> python:path('a/' + path('x/y') + '/c')

Thanks for these examples.  I'd only thought of the middle one,
(although the first one *should* have occurred to me since it's
essentially the flow I'd just described above).

I will make one final impassioned plea, and then remain forever silent
on this issue :) While the above methods will work, why not allow ${}
expansion in paths by default (ie. without needing to use python:)?
I'm willing to bet that I'm not the only one who thought that if it
worked in strings, it ought to work in paths too (what is a path, but
just string that gets traversed?).  To me, it seems like the principle
of least surprise.  Users expect that if it's spelled that way for
strings, it ought to be spelled that way for paths.  Having to use
python:path(string()) to "coerce" it isn't intuitve.

If I write up a proposal for the DiscussTALES page, would you be
willing to do another survey?  If the majority disagrees with me, I
will concede defeat :)

Thanks for hearing me out,
Brent

PS.  I guess I'm arguing somewhat vehemently because I want ZPT to be
the best that it can be.  I really do love Page Templates :) and I
think you guys have been doing an excellent job.  Here at Rice
University we're using them in a production site for coordinating
course materials between professors here and at several other schools.
ZPT was definitely the selling point that convinced us to go with
Zope.


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

"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