[xquery-talk] operations on derived numeric type

Benito van der Zander benito at benibela.de
Fri Aug 30 11:23:27 PDT 2013


>
>
> PS how many times will I forget that $x-1 is parsed as a variable 
> name.  A token allowed in a symbol *and* as an operator makes no 
> sense.  Old argument I'm sure. 


That's especially fun if you have an implementation that does not raise 
an error on an unknown variable name...



On 08/30/2013 04:07 PM, Michael Sokolov wrote:
> On 08/30/2013 07:11 AM, Benito van der Zander wrote:
>> Hi,
>> is it true that *all* operations on types derived from the numeric 
>> types return a value of one of the four base numeric types?
>> For example xs:byte(1) + xs:byte(1) or abs(xs:byte(1)).
>>
>> What's the point of even having these sub types then?
>
> It's really a headache to use the subtypes since you are constantly 
> fighting against the grain.  For example, if you write a function like:
>
> declare function local:factorial($x as xs:int) as xs:int {
>   if ($x < 2) then 1 else local:factorial($x - 1) * $x
> }
>
> You get various compilation errors
>
> You have to do something like:
>
> declare function local:factorial($x as xs:int) as xs:int {
>   if ($x < 2) then xs:int(1) else xs:int(local:factorial(xs:int($x - 
> 1)) * $x)
> };
>
> local:factorial (xs:int(10))
>
> This is using Saxon 9.4.  Somehow in MarkLogic there seems to be some 
> kind of automatic casting going on, and the first function compiles 
> and runs OK.
>
> -Mike
>
> PS how many times will I forget that $x-1 is parsed as a variable 
> name.  A token allowed in a symbol *and* as an operator makes no 
> sense.  Old argument I'm sure.
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk
>



More information about the talk mailing list