Content deleted Content added
No edit summary |
Attempt at defining cond |
||
Line 82:
::::::My point is that it is probably syntactically impossible, since cond uses some special syntactic rules that are treated specially by the Lisp interpreter. In other words, you'd have a problem getting the input into your "Turing machine" without encountering an interpreter error. Of course, I'd be happy to agree that you were correct if you can show us how to implement cond with lambda. -- [[User:CYD|CYD]]
Are you talking about the fact that cond is variadic? Besides that, keeping in mind that I don't know Lisp, how's this...
(defun true (y n) (y))
(defun false(y n) (n))
(defun cond(x) x)
In other words, with the right definitions of true and false, cond is a no-op. Or, if you don't like that one, there's this:
(defun cond(x) x)(
(ys eq ()) (n) -- If there are no predicated expression, return the "else"
(
(caar ys) (cadr ys) -- If the first predicate is true, return its expression
(cond (cdr ys) n) -- Otherwise recurse without the first predicated expression
)
)
This assumes eq returns either true or false as defined above. -- [[User:P3d0|P3d0]] 15:24, 24 Aug 2003 (UTC)
|