[Xpath-ng] List constructor syntax
Uche Ogbuji
uche.ogbuji at fourthought.com
Tue Dec 10 10:10:27 MST 2002
> Hi,
>
> If we should decide to go for lists with arbitrary content, including other
> lists,
> where singleton lists are not treated specially, we have to think a bit
> about the list constructor syntax.
>
> XPath 2.0 uses a comma separated list of items, often enclosed in
> parenthesis to create a sequence. The problem is how to create a list with
> only one item. Since the comma operator is an infix operator, it requires
> at least two operands. In XPath 2.0 this is no problem, since only flat lists
> are
> allowed, and an item is identicall to it's corresponding singleton sequence,
> so there's little need to create singleton sequences (and you can by '(1,
> ())').
> But if lists are just lists with no magical behavior (the way I want them)
> you'll
> want the ability to create singleton lists. Here are a couple of possibilities:
>
> Have a list function which takes zero or more arguments:
> list (1, 17) -- list with two items
> list (17) -- list with one item
> list () -- empty list
>
> This solution could be used alone or as a complement to the comma operator
> solution.
>
> Use square brackets or braces
> [1, 17] or {1, 17}
> [17] or {17}
> [] or {}
>
> Use parenthesis prefixed by a special character e.g. $
> $(1, 17)
> $(17)
> $()
>
> A variant of this and the function solution would be to
> name the function 'L' as in L(1, 17) and thus decrese the verbosity,
> but on the other hand it would be inconsistent with other core
> functions, which start with a lowercase character.
>
> My gut feeling is that the first list function solution is the cleanest and
> simplest.
> I could live with the square bracket version too, but I believe many will
> consider it
> too close to the filter syntax.
>
> Any other ideas?
Python uses an extra comma to disambiguate. i.e.
(1,2) is a tuple of length 2
(1) is an expression equivalent to "1"
(1,) is a tuple of length 1
(1,2,) is also a tuple of length 2 (i.e. the magic is general case)
--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://4Suite.org http://fourthought.com
Tour of 4Suite - http://www.xml.com/pub/a/2002/10/16/py-xml.html
Proper XML Output in Python - http://www.xml.com/pub/a/2002/11/13/py-xml.html
RSS for Python - http://www-106.ibm.com/developerworks/webservices/library/ws-p
yth11.html
Debug XSLT on the fly - http://www-106.ibm.com/developerworks/xml/library/x-deb
ugxs.html
More information about the Xpath-ng
mailing list