blob: 56e82945d41e03ff3ae5947d965c13b35800656a [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
22
23
swissChili484295d2021-07-09 21:25:55 -070024(defun not (val)
25 (nilp val))
swissChilif68671f2021-07-05 14:14:44 -070026
27;; TODO: make tail recursive (for this `flet` would be nice)
28(defun length (list)
swissChili15f1cae2021-07-05 19:08:47 -070029 "Returns the length of `list`, or `nil` if it is not a list"
swissChilif68671f2021-07-05 14:14:44 -070030 (if (nilp list)
31 0
32 (+ 1 (length (cdr list)))))
swissChili15f1cae2021-07-05 19:08:47 -070033
34(defmacro when (cond & body)
35 "Evaluate `body` when `cond` is truthy.
36When `cond` is truthy, evaluates `body` in order, finally evaluating to
37the final item."
38 (list 'if cond
39 (cons 'progn body)))
40
41(defmacro unless (cond & body)
42 "Evaluate `body` unless `cond` is truthy.
43When `cond` is nil, evaluates `body` in order, finally evaluating to the
44final item."
45 (list 'if cond
46 nil
47 (cons 'progn body)))
swissChili7e1393c2021-07-07 12:59:12 -070048
49(defun read ((stream nil))
50 (if (not stream)
51 (read-stdin)))
52
swissChili484295d2021-07-09 21:25:55 -070053(defun funcall (fun & list)
54 (print fun)
55 (print list)
56 (apply fun list))
57
58(load "list-functions.lisp")