<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>1583</bug_id>
          
          <creation_ts>2005-07-14 04:15:58 +0000</creation_ts>
          <short_desc>[FS] technical: 4.1.5 Function Calls: refactor</short_desc>
          <delta_ts>2005-09-27 08:28:56 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>Formal Semantics 1.0</component>
          <version>Last Call drafts</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michael Dyck">jmdyck</reporter>
          <assigned_to name="Jerome Simeon">simeon</assigned_to>
          
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>4557</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2005-07-14 04:15:58 +0000</bug_when>
    <thetext>4.1.5 Function Calls

DEv / rule (1|2|3)
    These three rules are all mostly the same (though that fact is
    obscured by irrelevant differences).  Refactor!
    You could have one rule that does almost everything, but &quot;calls out&quot;
    to a judgment that handles the essential differences between
    locally-declared, imported, and built-in/external functions. The new
    judgment would have a form something like:
        FUNC-REMAINDER applied to Value1, ..., Valuen yields Value
    where FUNC-REMAINDER is a symbol for &quot;the remainder of the function
    definition&quot; that dynEnv.funcDefn maps to.

    (The built-in/external alternative of the new judgment would subsume
    DEv / rule 4.)

    This would also allow refactoring of some of the DErr rules.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5250</commentid>
    <comment_count>1</comment_count>
    <who name="Jerome Simeon">simeon</who>
    <bug_when>2005-07-27 13:05:13 +0000</bug_when>
    <thetext>Agreed, we may find a better way to write those rules.
Here are some proposed rules to address the comment, trying to improve on the
readability for the existing rules.
- Jerome

Notations
---------

We should introduce a new formal grammar production:

  [Formal] FunctionSig ::= &quot;declare&quot; &quot;function&quot; QName &quot;(&quot; ParamList? (&quot;)&quot; | (&quot;)&quot;
&quot;as&quot; SequenceType))

Such production is notably used in the static context (for statEnv.funcType).


Dynamic semantics
-----------------

Here is the generic rule function function calls:

  dynEnv |- Expr1 =&gt; Value1
  ...
  dynEnv |- Exprn =&gt; Valuen
  statEnv |- QName of func expands to expanded-QName
  statEnv.funcType(expanded-QName) = { FunctionSig1, ..., FunctionSigm }
  FunctionSigi = declare function expanded-QName(Type1, ..., Typen) as Type
  statEnv |- Value1 against Type1 promotes to Value1&apos;
  ...
  statEnv |- Valuen against Typen promotes to Valuen&apos;
  dynEnv |- function expanded-QName with types (Type1,...,Typen) on values
(Value1&apos;,...,Valuen&apos;) yields Value
  statEnv |- Value against Type promotes to Value&apos;
 
-------------------------------------------------------------------------------------------
  dynEnv |- QName ( Expr1, ..., Exprn ) =&gt; Value&apos;


This uses the following auxiliary judgment:

  dynEnv |- function expanded-QName with types (Type1,...,Typen) on values
(Value1&apos;,...,Valuen&apos;) yields Value

which is defined as follows:

  * For user-defined functions:

  dynEnv.funcDefn(expanded-QName(Type1, ..., Typen)) = (Expr, Variable1, ... ,
Variablen)
  dynEnvDefault + varValue( Variable1 =&gt; Value1; ...; Variablen =&gt; Valuen) |-
Expr =&gt; Value
 
---------------------------------------------------------------------------------------------------------
  dynEnv |- function expanded-QName with types (Type1,...,Typen) on values
(Value1,...,Valuen) yields Value

  * For built-in or functions:

  dynEnv.funcDefn(expanded-QName(Type1, ..., Typen)) = #BUILT-IN
  &quot;The built-in function&quot; expanded-QName &quot;(See [Functions and
  Operators] or [7 Additional Semantics of Functions]) applied to&quot;
  (Value1,...Value2) &quot;yields the value&quot; Value
 
---------------------------------------------------------------------------------------------------------
  dynEnv |- function expanded-QName with types (Type1,...,Typen) on values
(Value1,...,Valuen) yields Value

  * For external functions:

  dynEnv.funcDefn(expanded-QName(Type1, ..., Typen)) = #EXTERNAL
  &quot;The external function&quot; expanded-QName &quot;applied to&quot;
  (Value1,...Value2) &quot;yields the value&quot; Value
 
---------------------------------------------------------------------------------------------------------
  dynEnv |- function expanded-QName with types (Type1,...,Typen) on values
(Value1,...,Valuen) yields Value

  * For imported functions:

  Note that this case also checks that the parameteres can be promoted
  in the context of the imported module.

  dynEnv.funcDefn(expanded-QName(Type1, ..., Typen)) = #IMPORTED(URI)
  URI =&gt;module_statEnv statEnv1
  URI =&gt;module_dynEnv dynEnv1
  statEnv1.funcType(expanded-QName) = { FunctionSig1&apos;, ..., FunctionSigm&apos; }
  FunctionSigi&apos; = declare function expanded-QName(Type1&apos;, ..., Typen&apos;) as Type&apos;
  dynEnv1.funcDefn(expanded-QName(Type1&apos;, ..., Typen&apos;)) = (Expr, Variable1, ...
, Variablen)
  statEnv1 |- Value1 against Type1 promotes to Value1&apos;
  ...
  statEnv1 |- Valuen against Typen promotes to Valuen&apos;
  dynEnvDefault + varValue( Variable1 =&gt; Value1; ...; Variablen =&gt; Valuen) |-
Expr =&gt; Value
 
---------------------------------------------------------------------------------------------------------
  dynEnv |- function expanded-QName with types (Type1,...,Typen) on values
(Value1,...,Valuen) yields Value


</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5258</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2005-07-28 00:46:25 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt;
&gt;   [Formal] FunctionSig ::= &quot;declare&quot; &quot;function&quot; QName &quot;(&quot; ParamList? (&quot;)&quot; | (&quot;)&quot;
&gt; &quot;as&quot; SequenceType))

This doesn&apos;t agree with your uses of the symbol:

&gt;   FunctionSigi = declare function expanded-QName(Type1, ..., Typen) as Type
&gt; ...
&gt;   FunctionSigi&apos; = declare function expanded-QName(Type1&apos;, ..., Typen&apos;) as Type&apos;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5259</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Dyck">jmdyck</who>
    <bug_when>2005-07-28 01:49:04 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; 
&gt;   * For imported functions:
&gt; 
&gt;   Note that this case also checks that the parameteres can be promoted
&gt;   in the context of the imported module.

I think XQuery 3.1.5 is saying that the conversion (incl. promotion) is done
once, but the resulting value must &quot;match the expected type&quot; twice (in both
modules). (Though I&apos;m not sure if there&apos;s a case where the two interpretations
would have different outcomes.)

If my reading is correct, then you&apos;d replace
&gt;   statEnv1 |- Value1 against Type1 promotes to Value1&apos;
&gt;   ...
&gt;   statEnv1 |- Valuen against Typen promotes to Valuen&apos;
with &apos;matches&apos; premises. But in either case, I think Type1 and Typen should be
Type1&apos; and Typen&apos; (the types in the signature in the defining module).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>5720</commentid>
    <comment_count>4</comment_count>
    <who name="Jerome Simeon">simeon</who>
    <bug_when>2005-09-06 15:28:58 +0000</bug_when>
    <thetext>Agreed on comment #2. Thanks for the catch. We should have the grammar match the
signature used in the rules.

I also agree on comment #3 (although it took me a while longer to get there.

I think both are good amendments to the proposal.

- Jerome</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6472</commentid>
    <comment_count>5</comment_count>
    <who name="Jerome Simeon">simeon</who>
    <bug_when>2005-09-27 08:28:49 +0000</bug_when>
    <thetext>The working groups have adopted the proposes resolution, with your amendments.
Best,
- Jerome</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>