I have the following Clojure code and I'm not sure why it's not working:
(defn match (x y &optional binds)
(cond
((eql x y) (values binds t))
((assoc x binds) (match (binding x binds) y binds))
((assoc y binds) (match x (binding y binds) binds))
((var? x) (values (cons (cons x y) binds) t))
((var? y) (values (cons (cons y x) binds) t))
(t
(when (and (consp x) (consp y))
(multiple-value-bind (b2 yes)
(match (car x) (car y) binds)
(and yes (match (cdr x) (cdr y) b2)))))))
(The code is translated from Paul Graham's ANSI Common Lisp book.)
When I run it, I get the following error:
java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol
clojure.lang.Compiler$CompilerException: NO_SOURCE_FILE:2: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol
at clojure.lang.Compiler.analyze(Compiler.java:3713)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:3848)
at clojure.lang.Compiler.analyze(Compiler.java:3698)
at clojure.lang.Compiler.access$200(Compiler.java:37)
at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:343)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:3858)
at clojure.lang.Compiler.analyze(Compiler.java:3698)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:3848)
at clojure.lang.Compiler.analyze(Compiler.java:3698)
at clojure.lang.Compiler.analyze(Compiler.java:3671)
at clojure.lang.Compiler.eval(Compiler.java:3895)
at clojure.lang.Repl.main(Repl.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at jline.ConsoleRunner.main(ConsoleRunner.java:69)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol
at clojure.lang.LazyCons.rest(LazyCons.java:64)
at clojure.lang.ASeq.count(ASeq.java:85)
at clojure.lang.RT.count(RT.java:486)
at clojure.lang.Cons.count(Cons.java:41)
at clojure.lang.Compiler.analyze(Compiler.java:3695)
... 16 more
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol
at clojure.lang.LazyCons.first(LazyCons.java:44)
at clojure.lang.LazyCons.rest(LazyCons.java:59)
... 20 more
Caused by: java.lang.IllegalArgumentException: Don't know how to create ISeq from: Symbol
at clojure.lang.RT.seqFrom(RT.java:465)
at clojure.lang.RT.seq(RT.java:448)
at clojure.seq__28.invoke(boot.clj:92)
at clojure.every_QMARK___596.invoke(boot.clj:1180)
at clojure.fn__1147$psig__1149.invoke(boot.clj:2155)
at clojure.map__602$fn__605.invoke(boot.clj:1214)
at clojure.lang.LazyCons.first(LazyCons.java:40)
... 21 more
What am I doing wrong here?