add and, or macro

This commit is contained in:
yoyo 2024-09-11 17:21:38 +09:00
parent 75e2344cbe
commit ba39b84914

View File

@ -1,8 +1,24 @@
(macro defun (name args body)
`(define ,name (lambda ,args ,body)))
(macro cond (expr . rest)
(if (not expr)
nil
(let ((test (car expr)))
`(if ,test
(progn ,test ,@(cdr expr))
(cond ,@rest)))))
(macro and (expr . rest)
(if (not rest)
expr
(if (cond (not expr) nil)
`(and ,@rest))))
(macro or (expr . rest)
(if rest
(cond (expr) (`(or ,@rest)))
expr))
(defun list (x . y) (cons x y))
(macro cond (expr . rest)
(if (not expr) nil
`(if ,(car expr) (progn ,@expr) (cond ,@rest))))