-
Notifications
You must be signed in to change notification settings - Fork 12
/
patch.shen
30 lines (26 loc) · 963 Bytes
/
patch.shen
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
(package shen []
(define resolve-macro-functions
[] Acc -> (reverse Acc)
[X | Xs] Acc -> (resolve-macro-functions
Xs (trap-error [(function X) | Acc] (/. E Acc)))
where (symbol? X)
[X | Xs] Acc -> (resolve-macro-functions Xs [X | Acc]))
(define macroexpand'
X -> (let Y (compose (value *macros*) X)
(if (= X Y)
X
(walk (/. Z (macroexpand' Z)) Y))))
\*
(define macroexpand
X -> (do (set *macros* (resolve-macro-functions (value *macros*)))
(macroexpand' X)))
*\
(defun macroexpand (X)
(do (set *macros* (resolve-macro-functions (value *macros*) []))
(macroexpand' X)))
(define add-macro
F -> (let MacroReg (value *macroreg*)
NewMacroReg (set *macroreg* (adjoin F (value *macroreg*)))
(if (= MacroReg NewMacroReg)
skip
(set *macros* [F | (value *macros*)])))))