syntax change to allow future pattern extension

[I mailed this to www-xml-query-comments on August 28, and I never
saw an answer.  I realize that my suggestions will probably get
rejected, because you're trying to get a standard out the door.
However, I do think the current syntax is problematic]

It would be nice if it were possible to experiment with an XQuery
superset that supports patterns, as in xduce.  I assume we don't want
patterns in XQuery 1.0, but I think it might be nice for a future or
exterimental extension.  This means being able to bind a variable to
some nested type sub-expression.  The problem is that the syntax in
the published working draft makes this rather awkward.

For patterns to be interesting, a DataType should be able to be more
general type expressions, and in the future contain patterns.  But the
syntax for Param is 'DataType? Variable'.  This is difficult to parse
if DataType can be more complex than a simple name.  I suggest changing
the order: 'Variable DataType?'.  I also suggest adding in a delimter
which both makes things easier to read and parse, and ties in better
with allowing patterns.  I suggest '::' as a delimiter, as in:
	   Param := Variable ("::" DataType)?
Using colon is familar from many other languages.  However, a single
colon can be confused with a namespace marker.  However, a double
colon does not have that problem.  Axis specifiers use the same syntax,
but in a different context, so there is no ambiguity.

I also suggest changing typeswitch to:

TypeSwitchExpr   ::=   "typeswitch" "(" Expr ")" CaseClause+
                        "default" "return" Expr
CaseClause   ::=   "case" [Variable "::"] Datatype "return" Expr

[Actually, I would suggest replacing the noise word "return" with
some less visually distracting and redundant punctuation, such as
some kind of arrow, but that is an orthogonal problem.]

Yes, this is a little more verbose in that the Variable has to be
specified for each CaseClause rather than sharing a single "as" clause.
However, it does allow picking different mnemonic names for each
CaseClause, and I think it is more readable.  More important,
this syntax is extensible to more general patterns, for example:

typeswitch ($w)
   case ($x::type1*),($y::type2) return use($x,$y)
   case $a::element a($x::type1*,$y::type2) return use($x,$y)
   default return ...

To repeat, I am not proposing general patterns for XQuery 1.0.
I am suggesting some syntax tweaks that improve the language
in themselves *and* allow experimentation for future extensions
using patterns.
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/

Received on Monday, 4 March 2002 03:01:25 UTC