-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathastruct.lisp
174 lines (164 loc) · 6.65 KB
/
astruct.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
(FILEHEADER ASTRUCT)
(PRINT '(ASTRUCTURE FUNCTIONS WRITTEN BY BLAKE MCBRIDE))
(PRINT '(VERSION 10))
(DEFINEQ
(ACHANGE
[LAMBDA (A K V)
(AND (LITATOM A)
(PROG ((L (GETPROP A 'AFRAME)))
(AND (NLISTP L) (RETURN))
[AND (NULL K)
(RETURN (RETURN (RPLACA L V]
(AND (NLISTP K) (SETQ K (CONS K)))
LP [COND ((NLISTP (SETQ L (CDR L))) (RETURN))
((NLISTP (CAR L)) (GO LP))
((MATCH (CAR K) (CAAR L))
(AND (NLISTP (SETQ K (CDR K)))
(RETURN (RPLACA (CAR L) V)))
(SETQ L (CAR L]
(GO LP])
(AGET
[LAMBDA (A K)
(AND (LITATOM A)
(PROG ((L (GETPROP A 'AFRAME)))
(AND (NLISTP L) (RETURN))
(AND (NULL K) (RETURN L))
(AND (NLISTP K) (SETQ K (CONS K)))
LP [COND ((NLISTP (SETQ L (CDR L))) (RETURN))
((NLISTP (CAR L)) (GO LP))
((MATCH (CAR K) (CAAR L))
(AND (NLISTP (SETQ K (CDR K)))
(RETURN (CAR L)))
(SETQ L (CAR L]
(GO LP])
(AGETNAMES
(LAMBDA (A K R)
[MAPC (CDR (AGET A K))
'(LAMBDA (A)
(AND (LISTP A)
(SETQ R (CONS (CAR A) R]
R))
(AMAKE
(LAMBDA (K V)
[MAPC (REVERSE K)
'(LAMBDA (K) (SETQ V (CONS (CONS K V]
V))
(AMEMBER
[LAMBDA (A K V)
(AND (LITATOM A)
(PROG ((L (GETPROP A 'AFRAME)))
(AND (NLISTP L) (RETURN))
[AND (NULL K)
(RETURN
(COND (V (AND (OR (MATCH V (CDR L))
(LMATCH V (CDR L)))
T))
(T]
(AND (NLISTP K) (SETQ K (CONS K)))
LP [COND ((NLISTP (SETQ L (CDR L))) (RETURN))
((NLISTP (CAR L)) (GO LP))
((MATCH (CAR K) (CAAR L))
[AND (NLISTP (SETQ K (CDR K)))
(RETURN
(COND (V (AND (OR (MATCH V
(CDAR L))
(LMATCH V
(CDAR L)))
T))
(T]
(SETQ L (CAR L]
(GO LP])
(APRINT
(LAMBDA (A K)
(AND (LISTP (SETQ A (AGET A K))) (APRINT1 A 0))))
(APRINT1
[LAMBDA (L N)
(PROG NIL
(SPACES N)
(PRINT (CAR L))
(SETQ N (PLUS 3 N))
LOOP (COND ((NULL (SETQ L (CDR L))) (RETURN))
((NLISTP L) (SPACES N) (PRINT L) (RETURN))
((NLISTP (CAR L))
(SPACES N)
(PRINT (CAR L))
(GO LOOP))
(T (APRINT1
(CAR L)
(COND ((GREATERP N 20) 0) (N)))
(GO LOOP])
(APUT
[LAMBDA (A K V F)
(AND (LITATOM A)
(PUTPROP A 'AFRAME
(PROG ((R (GETPROP A 'AFRAME)) L)
[AND (NULL K)
(RETURN
(COND ((NLISTP R) (CONS A V))
((RPLACD R V]
(AND (NLISTP K) (SETQ K (CONS K)))
[AND (NLISTP (SETQ L R))
(RETURN (CONS A (AMAKE K V]
LP1 (COND ((NLISTP (CDR L))
(RPLACD L
(APPEND (AMAKE K V) (CDR L)))
(RETURN R))
[(NLISTP (CAR (SETQ L (CDR L]
((MATCH (CAR K) (CAAR L))
(AND (LISTP (SETQ K (CDR K)))
(SETQ L (CAR L))
(GO LP1))
(RPLACD
(CAR L)
(COND (F (CONS V (CDAR L)))
(T V)))
(RETURN R)))
(GO LP1])
(AREM
(LAMBDA (X L L1)
[MAPC L
'(LAMBDA (A)
(OR (MATCH X A) (SETQ L1 (CONS A L1]
(REVERSE L1)))
(AREMOVE
[LAMBDA (A K V)
(AND (LITATOM A)
(PUTPROP A 'AFRAME
(PROG ((R (GETPROP A 'AFRAME)) L TMP)
(AND (NLISTP R) (RETURN R))
[AND (NULL K)
(RETURN
(RPLACD R
(COND (V (AREM V (CDR R)))
(T NIL]
(AND (NLISTP K) (SETQ K (CONS K)))
(SETQ L (CDR R))
LP1 (COND ((NLISTP L) (RETURN R))
((NLISTP (CAR L))
(SETQ L (CDR (SETQ TMP L)))
(GO LP1))
[(MATCH (CAR K) (CAAR L))
(AND (LISTP (SETQ K (CDR K)))
(PROGN
[SETQ L
(CDR (SETQ TMP (CAR L]
(GO LP1)))
(COND (V (RPLACD
(CAR L)
(AREM V (CDAR L)))
(RETURN R))
(T [AND (NULL TMP)
(RETURN
(RPLACD R (CDDR R]
(RPLACD TMP (CDR L))
(RETURN R]
(T (SETQ L (CDR (SETQ TMP L)))
(GO LP1])
)
(PRINT 'ASTRUCTFNS)
(RPAQQ ASTRUCTFNS
(ACHANGE AGET AGETNAMES AMAKE AMEMBER APRINT APRINT1 APUT AREM AREMOVE)
)
(RPAQQ ASTRUCTCOMS (ASTRUCTURE FUNCTIONS WRITTEN BY BLAKE MCBRIDE))
(RPAQ ASTRUCTGENNR 10)
STOP