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.
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' :)
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