プログラム言語論メモ (2024/11/18)
code:el
(defun fact-recursive (n)
(cond ((< n '1) '1)
('t (* n (fact-recursive (- n '1))))
(defun fact-tail-merge (n &optional queue)
(cond ((< n '1) (fact-execute-queue queue '1))
('t (fact-tail-merge (- n '1) (cons #'(lambda (x) (* n x)) queue)))) (defun fact-execute-queue (queue x)
(cond ((consp queue) (fact-execute-queue (cdr queue) (funcall (car queue) x)))
('t x)))
code:lisp
(list (car '(a b)) (car '(c d)))
→ (a c)
`(,(car '(a b)) ,(car '(c d)))
→ (a c)
`(a ,(car '(b c)) c)
→ (a b c)
code:el
(reverse '(1 2))
→ (2 1)
`(,(reverse '(1 2)))
→ ((2 1))
`(,@(reverse '(1 2)) )
→ (2 1)
`(a ,@(reverse '(1 2)) b)
→ (a 2 1 b)
(defmacro first (x) `(car ,x))
→ first
(macroexpand '(first '(a b c)))
(car '(a b c))
(first '(a b c))
→ a