“Don’t know how to create ISeq from: Symbol” error

647 views
Skip to first unread message

Paul Reiners

unread,
Dec 15, 2008, 12:34:04 PM12/15/08
to Clojure
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?

Randall R Schulz

unread,
Dec 15, 2008, 1:40:57 PM12/15/08
to clo...@googlegroups.com
On Monday 15 December 2008 09:34, Paul Reiners wrote:
> 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:
> ...

>
> What am I doing wrong here?

(assoc ...) is a function defined in the Clojure core:

user=> (doc assoc)
-------------------------
clojure.core/assoc
([map key val] [map key val & kvs])
assoc[iate]. When applied to a map, returns a new map of the
same (hashed/sorted) type, that contains the mapping of key(s) to
val(s). When applied to a vector, returns a new vector that
contains val at index. Note - index must be <= (count vector).


(binding ...) is a macro defined in the Clojure core:

user=> (doc binding)
-------------------------
clojure.core/binding
([bindings & body])
Macro
binding => var-symbol init-expr

Creates new bindings for the (already-existing) vars, with the
supplied initial values, executes the exprs in an implicit do, then
re-establishes the bindings that existed before.


I believe they're interfering with the use you're making of them in your
translated ACL code.

Have you defined all those other CL things that don't have direct
counterparts in Clojure? Things like (eql ...) and
(multiple-value-bind ...)?


Randall Schulz

kwatford

unread,
Dec 15, 2008, 1:56:45 PM12/15/08
to Clojure
> I have the following Clojure code and I'm not sure why it's not working:

The short answer is: That's not Clojure code, it is Common Lisp code.

Longer answer: Despite having similar-looking syntax, the two are not
particularly related. Of the functions/macros you tried to use, I
think only "and", "cons", and "when" simultaneously exist, have the
same syntax, and work in approximately the same way in Clojure as in
Common Lisp.

I would suggest reading some Clojure documentation.

James Reeves

unread,
Dec 15, 2008, 1:58:43 PM12/15/08
to Clojure


On Dec 15, 5:34 pm, Paul Reiners <paul.rein...@gmail.com> wrote:
> 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)))))))

There quite are a few things wrong with that code! Firstly, your
function definition is wrong:

(defn match [x y & binds]

Next, cond has too many parenthesis:

(cond
(eql x y) (values binds t)
...)

You use a lot of non-standard functions as well. Should (eql x y) be
(= x y)? What is (values binds t) meant to do? Is 't' really what you
mean, or do you want 'true'? And unless you've previously defined
'cdr' yourself, your probably want to use 'rest' instead.

There's really too much wrong with that function to exhaustively list
all the problems with it. Without knowing what other functions you've
defined already, though, I can't say for sure whether they are all
errors. You may have redefined cond and bound t to true. The only
certain thing I can say is incorrect is the function definition.

- James
Reply all
Reply to author
Forward
0 new messages