[Zope-dev] Re: TALES idea: tuple unpacking
Evan Simpson
evan@4-am.com
Wed, 30 Jul 2003 12:13:41 -0500
Jim Penny wrote:
> Well, that is exactly why it will be more confusing to everyone. A
> python programmer is not expecting them to be different, and a
> non-programmer has no idea of what keys and indices are, much less how
> they differ.
The explanation isn't that hard, at least for a user with a basic
knowledge of data structures -- you usually use key: with a dictionary,
and item: with a sequence. The exception is when you have an integer
key in a dictionary.
> Eeep, gad no. The python is horrible. The prefix syntax is equally
> horrible, unfamiliar, and ambiguous! For example, why does call: not
> have an argument
Because I'm not passing an argument to the SQL statement. In my
implementation, the syntax is "call:arg1,arg2,...", where each argument
is required to be a variable name. Every prefixed path element operates
upon the current traversal object, using the argument (if any) to the
prefix. Here's a list that demonstrates:
x/key:foo --> x['foo']
x/item:0 --> x[0]
x/attr:foo --> x.foo
x/call:foo --> x(foo)
x/var:foo --> getattr(x, foo) or x[foo] (path traversal semantics)
x/fmt:%.2f --> '%.2f' % x
x/fmt:thousands_commas --> thousands_commas(x)
> Yes, alternative is very nice. Yes, it can be done with python:path(),
> or by refactoring the expression to an script. Yes, the alternatives
> are harder to read, or more work. Nu?
I can't think of a way to implement my first example using
python:path(), though you could certainly do it with a Script. The
second example can be awkwardly rewritten by defining "exists:data/stat"
and using it in a short-circuiting boolean expression such as "have_stat
and thousands_commas(data.stat) or 'No data.'". My point is that these
prefixes allow a degree of precision, when necessary, that is not
possible in current TALES without totally transforming the expression.
> Doesn't it strike you as odd that sometimes the prefix denotes
> parameterization, and sometimes it denotes application?
I hope that the list above makes the consistency clearer.
Cheers,
Evan @ 4-am