3 ms·
His build implementation uses tail recursion which is not preferred in CL. One can build in a similar way that as shown at the end. (defun build (list-1 li
by PuercoPop 11y ago
His build implementation uses tail recursion which is not preferred in CL. One can build in a similar way that as shown at the end.
(defun build (list-1 list-2)
(loop
:for elem-1 :in list-1
:for elem-2 :in list-2
:collect (list elem-1 elem-2)))
A much bigger difference imho between Clojure and Common Lisp is that the former is built on abstractions, conj, while the latter is built on concrete cons cells. There are more other significant differences but I don't want to flame/argue.
- EdwardDiego 11y agoIs it even recursing in the tail position though? Reading the code it looks to me like the recursion result is used as an argument to a subsequent function call (append).
- rachbowyer 11y agoSpot on! The code fails as the author has used nil? rather than empty? The recursive call is not from the tail position so tail call optimisation is not possible in any language.
- PuercoPop 11y ago> tail call optimisation is not possible in any language. Afaik it is possible in racket. Read the note at the end here: http://matt.might.net/articles/lexers-in-racket/ http://matt.might.net/articles/lexers-in-racket/
- PuercoPop 11y agoYou are right, should have said recursion instead.