[Xpath-ng] List constructor syntax

David Rosenborg darolst at pantor.com
Thu Nov 28 15:46:08 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?

Cheers,
David




More information about the Xpath-ng mailing list