blob: db0cd128f8f33693e13b308b6bb66e7c66a8e0d0 [file] [log] [blame]
swissChilif68671f2021-07-05 14:14:44 -07001;;;; std.lisp -- Lisp standard library
2
swissChili15f1cae2021-07-05 19:08:47 -07003;; Boring utilities
4
swissChilif68671f2021-07-05 14:14:44 -07005(defun caar (val)
6 (car (car val)))
7
8(defun cadr (val)
9 (car (cdr val)))
10
11(defun caddr (val)
12 (car (cdr (cdr val))))
13
14(defun cadar (val)
15 (car (cdr (car val))))
16
17(defun caddar (val)
18 (car (cdr (cdr (car val)))))
19
swissChili15f1cae2021-07-05 19:08:47 -070020;; /Boring utilitites
21
swissChili484295d2021-07-09 21:25:55 -070022(defun not (val)
swissChili36f2c692021-08-08 14:31:44 -070023 "Identical to NILP, returns T if VAL is NIL, NIL otherwise."
swissChili484295d2021-07-09 21:25:55 -070024 (nilp val))
swissChilif68671f2021-07-05 14:14:44 -070025
26;; TODO: make tail recursive (for this `flet` would be nice)
27(defun length (list)
swissChili36f2c692021-08-08 14:31:44 -070028 "Returns the length of LIST, or NIL if it is not a list"
swissChilif68671f2021-07-05 14:14:44 -070029 (if (nilp list)
30 0
31 (+ 1 (length (cdr list)))))
swissChili15f1cae2021-07-05 19:08:47 -070032
33(defmacro when (cond & body)
swissChili15f1cae2021-07-05 19:08:47 -070034 (list 'if cond
35 (cons 'progn body)))
36
37(defmacro unless (cond & body)
swissChili15f1cae2021-07-05 19:08:47 -070038 (list 'if cond
39 nil
40 (cons 'progn body)))
swissChili7e1393c2021-07-07 12:59:12 -070041
42(defun read ((stream nil))
43 (if (not stream)
44 (read-stdin)))
45
swissChili484295d2021-07-09 21:25:55 -070046(defun funcall (fun & list)
swissChili484295d2021-07-09 21:25:55 -070047 (apply fun list))
48
swissChili36f2c692021-08-08 14:31:44 -070049;; (defmacro flet1 (func & body)
50;; `(let1 (,(car func) ,(cons 'lambda (cdr func)))
51;; ,@load))
52
53(list "body-functions.lisp")