-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathbuiltin.lisp
71 lines (58 loc) · 1.96 KB
/
builtin.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(coalton-library/utils::defstdlib-package #:coalton-library/builtin
(:use
#:coalton
#:coalton-library/classes)
(:export
#:unreachable
#:undefined
#:error ; re-export from classes
#:not
#:xor
#:boolean-not
#:boolean-or
#:boolean-and
#:boolean-xor))
(in-package #:coalton-library/builtin)
(named-readtables:in-readtable coalton:coalton)
#+coalton-release
(cl:declaim #.coalton-impl/settings:*coalton-optimize-library*)
(cl:defmacro unreachable (cl:&optional (datum "Unreachable") cl:&rest arguments)
"Signal an error with CL format string DATUM and optional format arguments ARGUMENTS."
`(lisp :a ()
(cl:error ,datum ,@arguments)))
(coalton-toplevel
(define (undefined _)
"A function which can be used in place of any value, throwing an error at runtime."
(error "Undefined"))
(define not
"Synonym for `boolean-not`."
boolean-not)
(define xor
"Synonym for `boolean-xor`."
boolean-xor)
(declare boolean-not (Boolean -> Boolean))
(define (boolean-not x)
"The logical negation of `x`. Is `x` false?"
(match x
((True) False)
((False) True)))
(declare boolean-or (Boolean -> Boolean -> Boolean))
(define (boolean-or x y)
"Is either `x` or `y` true? Note that this is a *function* which means both `x` and `y` will be evaluated. Use the `or` macro for short-circuiting behavior."
(match x
((True) True)
((False) y)))
(declare boolean-and (Boolean -> Boolean -> Boolean))
(define (boolean-and x y)
"Are both `x` and `y` true? Note that this is a *function* which means both `x` and `y` will be evaluated. Use the `and` macro for short-circuiting behavior."
(match x
((True) y)
((False) False)))
(declare boolean-xor (Boolean -> Boolean -> Boolean))
(define (boolean-xor x y)
"Are `x` or `y` true, but not both?"
(match x
((True) (boolean-not y))
((False) y))))
#+sb-package-locks
(sb-ext:lock-package "COALTON-LIBRARY/BUILTIN")