blob: 774d80546c354b8cc6c87339c1b8e7cc04db5d47 [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)
23 (nilp val))
swissChilif68671f2021-07-05 14:14:44 -070024
25;; TODO: make tail recursive (for this `flet` would be nice)
26(defun length (list)
swissChili15f1cae2021-07-05 19:08:47 -070027 "Returns the length of `list`, or `nil` if it is not a list"
swissChilif68671f2021-07-05 14:14:44 -070028 (if (nilp list)
29 0
30 (+ 1 (length (cdr list)))))
swissChili15f1cae2021-07-05 19:08:47 -070031
32(defmacro when (cond & body)
33 "Evaluate `body` when `cond` is truthy.
34When `cond` is truthy, evaluates `body` in order, finally evaluating to
35the final item."
36 (list 'if cond
37 (cons 'progn body)))
38
39(defmacro unless (cond & body)
40 "Evaluate `body` unless `cond` is truthy.
41When `cond` is nil, evaluates `body` in order, finally evaluating to the
42final item."
43 (list 'if cond
44 nil
45 (cons 'progn body)))
swissChili7e1393c2021-07-07 12:59:12 -070046
47(defun read ((stream nil))
48 (if (not stream)
49 (read-stdin)))
50
swissChili484295d2021-07-09 21:25:55 -070051(defun funcall (fun & list)
swissChili484295d2021-07-09 21:25:55 -070052 (apply fun list))
53
54(load "list-functions.lisp")