-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathbuiltin.lisp
76 lines (63 loc) · 2.09 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
72
73
74
75
76
(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"))
(inline)
(declare not (Boolean -> Boolean))
(define (not x)
"Synonym for `boolean-not`."
(boolean-not x))
(inline)
(declare xor (Boolean -> Boolean -> Boolean))
(define (xor x y)
"Synonym for `boolean-xor`."
(boolean-xor x y))
(inline)
(declare boolean-not (Boolean -> Boolean))
(define (boolean-not x)
"The logical negation of `x`. Is `x` false?"
(lisp Boolean (x)
(cl:not x)))
(inline)
(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."
(lisp Boolean (x y)
(cl:or x y)))
(inline)
(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."
(lisp Boolean (x y)
(cl:and x y)))
(inline)
(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")