-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtype.lisp
More file actions
60 lines (49 loc) · 1.39 KB
/
Copy pathtype.lisp
File metadata and controls
60 lines (49 loc) · 1.39 KB
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
(in-package nock)
(in-readtable :standard)
(deftype notom ()
"NOck aTOM: an unsigned integer"
'(integer 0))
(deftype noun ()
'(or cons notom))
(deftype nondex ()
"NOck iIDEX: a value suitable for 0"
'positive-fixnum)
(deftype formula ()
"Nock formula, or Hoon gate: gets a noun, returns a noun."
'(function (noun) noun))
(deftype noolean ()
"Nock bOOLEAN"
'(member 0 1))
(declaim (inline noolify))
(defun noolify (value)
(if value 0 1))
(defstruct worm
"Wrapped fORMula"
(formula (error "no formula to wrap") :read-only t :type formula)
(original (error "no noun to wrap") :read-only t :type noun))
(declaim (inline original))
(defun original (thing)
(typecase thing
(worm (worm-original thing))
(t thing)))
(declaim (inline carn))
(defun carn (noun)
"CAR of Noun.
Compiled formulae are cached by way of replacing the respective noun's
car with a worm. But we still need the ability to treat the noun as
noun."
(original (car noun)))
(locally
(declare #.*optimize-speed*)
(defun eqn (b c)
"Equality predicate for nouns.
We cannot just use EQUAL, because of worms."
(or (eql b c)
(and (consp b) (consp c)
(eqn (carn b) (carn c))
(eqn (cdr b) (cdr c))))))
(defun deworm (noun)
(etypecase noun
(cons (cons (deworm (car noun)) (deworm (cdr noun))))
(notom noun)
(worm (deworm (worm-original noun)))))