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