Can Clojure protocol functions be variables like regular functions?

Using the clojure functions, I can determine:

(defn f [x & xs] (apply some-function x xs)) 

I am trying to do the same with a protocol, for example.

 (defprotocol foo (bar [f]) (baz [f & gs])) 

This compiles (at least in the REPL), but any type of implementation seems to fail in this (variational, basic) method. Is this officially not supported? The sources I consulted are silent.

+10
clojure protocols
Mar 23 2018-11-11T00:
source share
2 answers

This is not supported, for the reasons that Stuart Sierra gives. To move on to a more detailed description, the & character is special only in the context of destructuring, such as let or function arguments. As Stuart clearly shows, defprotocol not such a context.

But & is still a legal symbol, so you defined a protocol with two functions: bar takes one argument with the name f and baz takes three with the name f , & and gs .

+10
Mar 23 '11 at 15:58
source share

As Stuart Sierra replied to the next thread , variative methods are not supported and may not be supported in the future.

+8
Mar 23 '11 at 7:50
source share



All Articles