[Bug 8662] [XQuery 1.1] Need an easy way to define a recursive inline function

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





--- Comment #8 from John Snelson <john.snelson@oracle.com>  2010-02-05 23:20:12 ---
(In reply to comment #7)
> There are some uncertainties in the syntax. For one thing, the suggested syntax
> looks like a variable binding, complete with $ - but then functions are called
> without using $, as if they were true local functions and not variables:
> 
>    local $even := ...
>    ...
>    even(abs($a) - 1)

That's an unfortunate typo - thanks for spotting it. Of course, the functions
should be called using the variables ($even in the quoted example).

> Also, the syntax itself is, IMO, too generic-looking while being specialized.
> In particular, keyword "local", on one hand, does not in any way indicate the
> main difference from "let" (scope of bound identifiers), and on the other hand,
> looks like a general-purpose local variable declaration, even though it cannot
> actually be used as such.

I thought that "local" was more descriptive then "letrec", but maybe I've been
looking at the syntax for too long.

> One idea would be to allow "letrec" (given that XQuery syntax is traditionally
> verbose, "let recursive" looks more in-line with the existing language) as
> described in point #3, but restrict initializer to inline function on grammar
> level. Such a restriction would fully enable this particular use case, and also
> allow for further extensions, if they are deemed desirable (e.g. mutually
> recursive lazy sequences a la Haskell, etc). It is also rather
> self-descriptive. So:
> 
>   let recursive
>     $even := function($a)
>     {
>       if($a == 0) then true()
>       else $odd(abs($a) - 1)
>     },
>     $odd := function($a)
>     {
>       if($a == 0) then false()
>       else $even(abs($a) - 1)
>     }
>   return ($even, $odd) 
> 
> is fine, but neither:
> 
>    let recursive $x := $y, $y := $x
> 
> nor
> 
>    let recursive $x := 1, $y := 2
> 
> is not, because the expression must be an inline function.

The proposal already restricts the variable binding expressions to be inline
functions. I think that "let recursive" is a reasonable alternative syntax that
should be considered.


-- 
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 Friday, 5 February 2010 23:20:14 UTC