[Bug 11792] New: lack of syntactic symmetry between the control flow expressions

http://www.w3.org/Bugs/Public/show_bug.cgi?id=11792

           Summary: lack of syntactic symmetry between the control flow
                    expressions
           Product: XPath / XQuery / XSLT
           Version: Member-only Editors Drafts
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XQuery 3.0
        AssignedTo: jonathan.robie@redhat.com
        ReportedBy: dflorescu@mac.com
         QAContact: public-qt-comments@w3.org


Dear all,

please look at the syntax of three of the control flow expressions that are
available in XQuery 3.0,
 that look very similar in functionality and structure, but slightly dissimilar
in grammar.

Those are switch, typeswitch and try catch.

The (simplified) grammar is bellow:

----------

'typeswitch' '(' Expr ')'   ( 'case'  ( VarName 'as' ) ? SequenceType 'return'
Expr )+   'default'  VarName ?  'return' Expr

'switch'  '('  Expr ')'  ( 'case' Expr   'return' Expr ) + 'default' 'return'
Expr

'try'  '{' Expr '}'  (  'catch' CatchErrorList   CatchVars?   '{' Expr '}'  )+

----------

Each one of them has:
(a) a main expression to evaluate  and
(b) several branches,  one of them being evaluated and the result being
returned, the choice 
being based on the presence of some particular events: a certain type, a
certain value or a 
certain error.

And they are all three expressions, all three of them returning instances of
XDM.

Let's look at  examples of each of them.


typeswitch (  $x div $y ) 
    case xs:integer return "First branch" 
    case xs:decimal return "Second branch"
    default "Last branch"

switch (  $x div $y ) 
    case 3 return "First branch" 
    case 4 return "Second branch"
    default "Last branch"

try  {  $x div $y }
    catch err:FOAR0001  { "First branch" }
    catch err:FOAR0003  { "Second branch" }
    catch *  { "Last branch" }

The lack of syntactical similarity and symmetry between them is very difficult
for a user
(I can never remember what to use where..).

The two major differences are:
(a) the use of () vs. {} in switch/typeswitch  vs. trycatch for the main Expr
to be evaluated
(b) the use of the keyword 'return' vs the use of {} in in switch/typeswitch 
vs. trycatch
for the Expr to be returned

There is no reason for those syntactic differences.

Users can only be confused by that.

Could we please make them grammatically symmetrical ?

Best regards
Dana

-- 
Configure bugmail: http://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Tuesday, 18 January 2011 16:39:57 UTC