beowulf/resources/sexpr/fact.lsp
Simon Brooke d563f390c1
#7: Progress! No longer breaking!
Bug is now probably in the implementation of CONC rather than in EVAL.
2023-04-16 11:54:57 +01:00

23 lines
439 B
Common Lisp

;; Common Lisp
(defun range (max &key (min 0) (step 1))
(loop for n from min below max by step
collect n))
(mapcar #'(lambda (x) (+ x 1)) (range 10))
(defun factoriali (n)
(reduce #'* (range (+ n 1) :min 1 :step 1)))
(defun factorialr (n)
(cond ((= n 1) 1)
(t (* n (factorialr (- n 1))))))
;; Clojure
(defn factorial [n]
(reduce *' (range 1 (+ n 1))))
(defn expt [n x]
(reduce *' (repeat x n)))