You don't really need them, they're just syntactical sugar making the code more readable for everybody familiar with functional programming.
- `head($sequence)` could be written as `$sequence[1]`
- `tail($sequence)` could be written as `$sequence[position()>1]`
-- 
Jens Erat
 [phone]: tel:+49-151-56961126
  [mail]: mailto:email@jenserat.de
[jabber]: xmpp:jabber@jenserat.de
   [web]: 
http://www.jenserat.de
     PGP: 350E D9B6 9ADC 2DED F5F2  8549 CBC2 613C D745 722B
Am 20.05.2013 um 16:31 schrieb Marco Lettere 
marco.lettere@dedalus.eu:
> Thanks a lot.
> I'm really wondering how I was able to overlook "head" and "tail" .... maybe the age .... :-(
> 
> M.
> 
> On 05/20/2013 03:44 PM, Jens Erat wrote:
>> hi Marco,
>> 
>> using recursion is easily possible (and the only way to solve that problem without using maps), just write a small XQuery function like
>> 
>>   declare function local:interprete($operations as item()*, $set as item()*) as item()* {
>>     let $op := head($operations)
>>     let $ops := tail($operations)
>>     let $intermediate :=
>>       switch($op/@operator)
>>         case "UNION" return ($set, $op/item[not(@name = $set/@name)])
>>         case "INTERSECT" return $set[@name = $op/item/@name]
>>         case "DIFFERENCE" return $set[not(@name = $op/item/@name)]
>>         default return error()
>>     return
>>       if ($ops)
>>       then
>>         local:interprete($ops, $intermediate)
>>       else $intermediate
>>   };
>> 
>> Which you would call using `local:interpret(//set, ())`. I guess the code should be small enough to be self-explaining. I seems to work, but I didn't test with much more than the input you provided, better do some additional tests on production data before using it.
>> 
>> If you want to compare whole nodes instead of their name attribute, use `fn:deep-equal()` instead of the name comparisons. You will have to use some explicit loop, [quantified expressions] should get handy for that.
>> 
>> Regards from Lake Constance, Germany,
>> Jens Erat
>> 
>> [quantified expressions]: 
http://www.w3.org/TR/xpath20/#id-quantified-expressions
>> 
> 
> _______________________________________________
> BaseX-Talk mailing list
> BaseX-Talk@mailman.uni-konstanz.de
> 
https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk