| I am reading parts of On Lisp and playing around with Arc and as a simple exercise I translated the acond in On Lisp to Arc. For people new to the idea of macros (like me), I think this is a good starting exercise. I suggest you try it yourself before looking at the Arc version. The existing On Lisp code is: (defmacro acond (&rest clauses)
(if (null clauses)
nil
(let ((cl1 (car clauses))
(sym (gensym)))
`(let ((,sym ,(car cl1)))
(if ,sym
(let ((it ,sym)) ,@(cdr cl1))
(acond ,@(cdr clauses)))))))
My port to Arc is: (mac acond clauses
(if (no clauses)
nil
(w/uniq g
(let cl1 (car clauses)
`(let ,g ,(car cl1)
(if ,g
(let it ,g ,@(cdr cl1))
(acond ,@(cdr clauses))))))))
A quick test to verify that acond works is: (= airport (table))
(= (airport 'yyz) "Toronto")
(acond ((airport 'sfo) (prn "This won't print " it))
((airport 'yyz) (prn "I'm flying to " it)))
|