defprotocol's support for variadic arguments seems broken

69 views
Skip to first unread message

Zach Tellman

unread,
Apr 6, 2010, 1:16:53 AM4/6/10
to Clojure
Possibly this fall out from the latest commit requiring an explicit
'this' reference (ba6cc3b), I haven't checked any versions but the
most recent.

user> (defprotocol Protocol (f [a b & c]))
Protocol
user> (def p (reify Protocol (f [a b & c] [a b c])))
#'user/p
user> (f p :a)
No single method: f of interface: user.Protocol found for function: f
of protocol: Protocol
user> (f p :a :b)
No single method: f of interface: user.Protocol found for function: f
of protocol: Protocol
user> (f p :a :b :c)
[#<user$reify__1503 user$reify__1503@31e2ad> :a :c]
user> (f p :a :b :c :d)
No single method: f of interface: user.Protocol found for function: f
of protocol: Protocol

Even the one signature that doesn't result in an exception doesn't
seem right.

Jarkko Oranen

unread,
Apr 6, 2010, 5:32:16 AM4/6/10
to Clojure

On Apr 6, 8:16 am, Zach Tellman <ztell...@gmail.com> wrote:
> Possibly this fall out from the latest commit requiring an explicit
> 'this' reference (ba6cc3b), I haven't checked any versions but the
> most recent.
>
> user> (defprotocol Protocol (f [a b & c]))
> Protocol
> user> (def p (reify Protocol (f [a b & c] [a b c])))
> #'user/p

> user> (f p :a :b :c)


> [#<user$reify__1503 user$reify__1503@31e2ad> :a :c]

Did protocols ever support variadic arguments? It seems to me that in
this case & gets treated as a regular symbol and a gets bound to the
object itself, b to :a, & to :b and c to :c, which would explain the
weird output.

Zach Tellman

unread,
Apr 6, 2010, 1:39:45 PM4/6/10
to Clojure
You're right, that does explain it. I assumed that variadic arguments
were supported, but maybe I was wrong. Can anyone confirm whether or
not this was ever intended to work?
Reply all
Reply to author
Forward
0 new messages