blob: 4e2166e663f759724eb845ae0a183c4b8eaa831b [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
swissChilifc5c9412021-08-08 19:08:26 -070049(defmacro flet1 (func & body)
50 `(let1 (,(car func)
51 (lambda ,@(cdr func)))
52 ,@body))
53
54(defun flet- (funcs body)
55 (if funcs
56 `(flet1 ,(car funcs)
57 ,(flet- (cdr funcs)
58 body))
59 `(progn ,@body)))
60
61(defmacro flet (funcs & body)
62 ;; (flet- funcs body)
63 (print funcs))
swissChili36f2c692021-08-08 14:31:44 -070064
swissChili1e8b7562021-12-22 21:22:57 -080065(load "list-functions.lisp")