[ZPT] sequence unpacking syntax in TAL
Charlie Clark
charlie at begeistert.org
Mon Jul 14 16:17:54 EDT 2003
On 2003-07-14 at 00:14:45 [+0200], Dieter Maurer wrote:
> > By analogy with this, we could also provide limited dict "unpacking"
> > for keys that are valid variable names (common case in my experience),
> > like tal:define="{key1 key2} mapvar".
>
> Didn't we want to keep TAL as simple as possible?
> Wasn't out motto: simple (and explicite) is beautyful.
While I can understand tuple unpacking in TAL working just as in Python I
must agree with Dieter that TAL should be kept as simple as possible. It's
become second nature to me to write PythonScripts to work with TAL.
Looking at the supplied examples:
<div tal:define=
"userid, host python:context.email_address.split('@', 1)"
>
This seems highly contrived and unrepresentative and not the kind of TAL I
would like to leave for anyone to have to figure out.
By extension, this should be useful with tal:repeat loops as well:
<tr tal:repeat=
"userid, name, email, favcolor context/user_info"
>
<td tal:content="userid"> user id </td>
<td><a href="mailto:address"
tal:attributes="href string:mailto:$email"
tal:content="name"> user name </a></td>
<td>Favorite color:
<span tal:replace="favcolor"> color name </span> </td>
</tr>
While this makes more sense I had to do a double-take as to why it is
tal:repeat and not tal:define. I think I would have problems with this and
I don't see any significant advantage over
<tr tal:repeat results context/user_info>
<td tal:content="results/userid">
</tr>
The namespace remains clear because it is explicit and all we have is some
additional typing.
If <tal:define="a, b, c, d 1, 2, 3, 4"> is to be allowed then I do not
agree with Evan's suggestion for new syntax for what would be a special
case but
<tal:define="(a, b, c, d) (1, 2, 3, 4)"> should be allowed for legibility.
Unpacking errors due should be presented as such with no catchalls: you
have to know what you're doing with tuple-unpacking and there is no need to
duplicate Python functionality.
Just my thoughts.
Charlie
More information about the ZPT
mailing list