Good evening Ladies and Gents, I am trying to convert the following into arc. In particular I am having difficulty converting the binding function. I think it involves using rfn and returning a list containing (cdr b) and b. Please find enclosed the link and code.
http://unintelligible.org/onlisp/onlisp.html#SEC119 (defun match (x y &optional binds)
(acond2
((or (eql x y) (eql x '_) (eql y '_)) (values binds t))
((binding x binds) (match it y binds))
((binding y binds) (match x it binds))
((varsym? x) (values (cons (cons x y) binds) t))
((varsym? y) (values (cons (cons y x) binds) t))
((and (consp x) (consp y) (match (car x) (car y) binds))
(match (cdr x) (cdr y) it))
(t (values nil nil))))
(defun varsym? (x)
(and (symbolp x
(eq (char (symbol-name x) 0) #\?)))
(defun binding (x binds)
(labels ((recbind (x binds)
(aif (assoc x binds)
(or (recbind (cdr it) binds)
it))))
(let ((b (recbind x binds)))
(values (cdr b) b))))
I'm wondering if this is close (def binding (x binds)
(assign b
(rfn recbind (x bind)
(aif (assoc x binds)
(or (recbind (cdr it) binds)
it)))))
(list (cdr b) b))
|