#7: Progress! No longer breaking!
Bug is now probably in the implementation of CONC rather than in EVAL.
This commit is contained in:
parent
d2ce61e6a7
commit
d563f390c1
4 changed files with 111 additions and 30 deletions
22
resources/sexpr/fact.lsp
Normal file
22
resources/sexpr/fact.lsp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
;; 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)))
|
||||
13
resources/sexpr/select.lsp
Normal file
13
resources/sexpr/select.lsp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
;; Bottom of page 66
|
||||
|
||||
(PUT 'SELECT 'FEXPR
|
||||
'(LABEL FORM
|
||||
(PROG (Q BODY)
|
||||
(SETQ Q (EVAL (CAR FORM))) ;; not sure that Q should be evaled.
|
||||
(SETQ BODY (CDR FORM))
|
||||
LOOP
|
||||
(COND
|
||||
((EQ NIL (CDR BODY)) (RETURN (CAR BODY)))
|
||||
((EQ Q (EVAL (CAAR BODY))) (RETURN (CDAR BODY))))
|
||||
(SETQ BODY (CDR BODY))
|
||||
(GO LOOP))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue