[sc34wg3] TMQL: function-invocation and parameters

Robert Barta rho at devc.at
Wed Feb 25 13:42:16 EST 2009

On Mon, Feb 23, 2009 at 08:48:27PM +0100, Lars Heuer wrote:
> >> I wonder why 'asc' / 'desc' should be allowed for function
> >> invocations and I have the suspicion that "parameters" references
> >> "tuple-expression" to save a grammar production.

> In my opinion a function invocation is different and legitimates
> therefor a special rule. If I'd understand why making
>    function null
> equivalent to
>    function()
> is a Good Thing and why asc / desc should be allowed for functions
> (see below), I may change my opinion, though. ;)

The following is a summary of a discussion at the #topicmaps IRC


Yes, this is the place where the supermodels (Lars^2) hang out.


There are two issues:

The first is that the phrase

    my:fancyfunction ()

can be written as

    my:fancyfunction null

just because the empty sequence () can also be written as


  [P] http://kill.devc.at/system/files/tmql-2008-07-15.html#tuple-expression

There are two possible reactions to this:

  A) "Who cares, so why not?"

  B) "Oh, this looks as if the universe explodes and the terrorists win."

If (B) is a common thinking, then we can simply remove [P] and move on. The
motivation to have something like null is to allow developers to write

  if .... then
     ... return null


The other issue is more fundamental and has to do how functions are
dealt with in TMQL. One obvious use is

   for $p in // person
       emp:age ($p / birthdate)

So first the birthdate(s) is computed and then injected into the function.
But the above can be rewritten into

       emp:age (// person / birthdate)

as it does the same thing:

   - first compute all persons,
   - then all their birthdates
   - then for each of the birthdate convert that into an age

If you look closer (and forget for a second the Modula/Pascal/C/Java syntax
for functions, then you will see first the computation of a tuple sequence
of birthdates

   (// person / birthdate)

TMQL already has this concept, so why have another special syntax for
it? That a function is applied to the above tuple sequence is then
written as

   emp:age (// person / birthdate)
              tuple - sequence

On Mon, Feb 23, 2009 at 08:48:27PM +0100, Lars Heuer wrote:

> I do not understand this. As you've mentioned, the "desc" belongs to
> the path expression "//person" and is evaluated before the
> tuple sequence is passed into the function.

Yes, any ordering is done to the tuple sequence BEFORE that is
injected into the function.

> Even if we'd define function-invocation as follows:
>   function-invocation ::= item-reference '(' parameters? ')'
>   parameters ::= value-expression (',' value-expression)*
> we'd get the same result, wouldn't we?

I do not think that is to the reordering issue. My argument is

  "why would I invent a new syntax rule for something I already have
   in the language?"


More information about the sc34wg3 mailing list