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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---