#7: Progress! No longer breaking!

Bug is now probably in the implementation of CONC rather than in EVAL.
This commit is contained in:
Simon Brooke 2023-04-16 10:51:17 +01:00
parent d2ce61e6a7
commit d563f390c1
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
4 changed files with 111 additions and 30 deletions

22
resources/sexpr/fact.lsp Normal file
View 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)))

View 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))))