swissChili | f68671f | 2021-07-05 14:14:44 -0700 | [diff] [blame] | 1 | ;;;; std.lisp -- Lisp standard library |
| 2 | |
swissChili | 15f1cae | 2021-07-05 19:08:47 -0700 | [diff] [blame] | 3 | ;; Boring utilities |
| 4 | |
swissChili | f68671f | 2021-07-05 14:14:44 -0700 | [diff] [blame] | 5 | (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 | |
swissChili | 15f1cae | 2021-07-05 19:08:47 -0700 | [diff] [blame] | 20 | ;; /Boring utilitites |
| 21 | |
swissChili | 484295d | 2021-07-09 21:25:55 -0700 | [diff] [blame] | 22 | (defun not (val) |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 23 | "Identical to NILP, returns T if VAL is NIL, NIL otherwise." |
swissChili | 484295d | 2021-07-09 21:25:55 -0700 | [diff] [blame] | 24 | (nilp val)) |
swissChili | f68671f | 2021-07-05 14:14:44 -0700 | [diff] [blame] | 25 | |
| 26 | ;; TODO: make tail recursive (for this `flet` would be nice) |
| 27 | (defun length (list) |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 28 | "Returns the length of LIST, or NIL if it is not a list" |
swissChili | f68671f | 2021-07-05 14:14:44 -0700 | [diff] [blame] | 29 | (if (nilp list) |
| 30 | 0 |
| 31 | (+ 1 (length (cdr list))))) |
swissChili | 15f1cae | 2021-07-05 19:08:47 -0700 | [diff] [blame] | 32 | |
| 33 | (defmacro when (cond & body) |
swissChili | 15f1cae | 2021-07-05 19:08:47 -0700 | [diff] [blame] | 34 | (list 'if cond |
| 35 | (cons 'progn body))) |
| 36 | |
| 37 | (defmacro unless (cond & body) |
swissChili | 15f1cae | 2021-07-05 19:08:47 -0700 | [diff] [blame] | 38 | (list 'if cond |
| 39 | nil |
| 40 | (cons 'progn body))) |
swissChili | 7e1393c | 2021-07-07 12:59:12 -0700 | [diff] [blame] | 41 | |
| 42 | (defun read ((stream nil)) |
| 43 | (if (not stream) |
| 44 | (read-stdin))) |
| 45 | |
swissChili | 484295d | 2021-07-09 21:25:55 -0700 | [diff] [blame] | 46 | (defun funcall (fun & list) |
swissChili | 484295d | 2021-07-09 21:25:55 -0700 | [diff] [blame] | 47 | (apply fun list)) |
| 48 | |
swissChili | 36f2c69 | 2021-08-08 14:31:44 -0700 | [diff] [blame] | 49 | ;; (defmacro flet1 (func & body) |
| 50 | ;; `(let1 (,(car func) ,(cons 'lambda (cdr func))) |
| 51 | ;; ,@load)) |
| 52 | |
| 53 | (list "body-functions.lisp") |