Hi Marc,
interesting question! Although I don't actually now the answer, I think there is an easy work-around for this one. Simply use string-join() instead of concat, i.e.
declare variable $concat := fn:string-join#1;
It will yield the same result.
I don't actually know how to properly handle the variable number of arguments for fn:concat to use as function items, so the core of your question is quite interesting. However, I think that concat even has a variable number of arguments is rather strange and impractical (normally simply a sequence of items is used in lots of other function declarations). According to the spec (http://www.w3.org/TR/xpath-functions/#func-concat) it sounds very much this is due to backwards compatibility. I am sure someone from our team with more function-item knowledge than I am knows the answer how (or if?) this can be done.
By the way, your project sounds quite interesting! I only have a very slight idea what it actually is (because I am not really familiar with the technologies you mentioned and compared it to), but handling HTTP routing sounds and porting from Clojure sounds good to me.
Cheers, Dirk
On 13/08/14 22:15, Marc van Grootel wrote:
Hi,
I am trying to call an anonymous function with a variable argument list.
Maybe I'm overlooking something within XQuery but I cannot figure out how to do this.
This is the code I would like to get working.
declare function local:apply($fn, $args) { $fn($args) };
declare variable $concat := fn:concat#3; declare variable $args := ('a', 'b', 'c'); (: needs to handle any list of strings :) local:apply($concat, $args) (: => 'abc' :)
What I want local:apply to do is similar to apply in some function languages such as Clojure ( http://clojuredocs.org/clojure_core/clojure.core/apply)
In the code above I have two problems. a) how to bind the fn:concat function to a variable. Arity? #1, #2 ... ? b) how to "apply" a variable argument list to the function passed in to local:apply.
I figure I could do something maybe with some other higher order functions but I cannot see the solution. I don't mind rtfm responses, I may have missed it.
I keep bombarding the list with questions so it is only fair to give a bit of context. I am porting parts of a few small Clojure libraries to XQuery, most important libraries are Ring and Compojure which are libraries for use in web frameworks. My implementation currently builds on top of RESTXQ but eventually can provide an alternative way of handling HTTP routing requests through function handlers (without function annotations). This is similar to WSGI in Python and Rack in Ruby. I would've liked to release this sooner but it is more work than anticipated and I want to provide something that does these ideas justice. So it's ready when it's ready ;-) but I'm pretty close. I'm currently finalizing the routing part and need to work some more on middleware handlers. Until then go look at https://github.com/ring-clojure to see what this is about.
--Marc