Skip to content

Commit edfbc70

Browse files
macro rules are working well, but patterns are legitimately complicated
1 parent 143275d commit edfbc70

File tree

1 file changed

+52
-50
lines changed

1 file changed

+52
-50
lines changed

STDLIB/default-rules.lm

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,56 @@ macro ( ('let x y) )
44

55
macro ('match t ps) (tail(
66
(let (uuid term) t)
7-
(let (uuid matched) ())
8-
(let (uuid return) ())
9-
(match-pats( (uuid term) (uuid matched) (uuid return) ps ))
10-
(uuid return)
7+
# (let (uuid matched) ())
8+
9+
# (let (uuid return) ())
10+
(print (uuid term))
11+
# (match-pats( (uuid term) (uuid matched) (uuid return) ps ))
12+
# (uuid return)
1113
));
12-
macro ('match-pats( term matched return () )) ();
13-
macro ('match-pats( term matched return (ps (lhs rhs)) )) (
14-
(match-pats( term matched return ps ))
15-
(if matched () (
16-
(set matched True)
17-
(match-destructure( term matched return lhs ))
18-
(if matched (
19-
(set return rhs)
20-
) ())
21-
))
22-
);
23-
macro ('match-destructure( term matched return () )) (
24-
(if matched (
25-
(if term (
26-
(set matched ())
27-
) ())
28-
) ())
29-
);
30-
macro ('match-destructure( term matched return (:Literal: l) )) (
31-
(if matched (
32-
(if (is-atom term) (
33-
(if (eq( term l )) () (
34-
(set matched ())
35-
))
36-
) (
37-
(set matched ())
38-
))
39-
) ())
40-
);
41-
macro ('match-destructure( term matched return (:Variable: v) )) (
42-
(let v term)
43-
);
44-
macro ('match-destructure( term matched return (l r) )) (
45-
(if matched (
46-
(if (is-cons term) (
47-
(let (uuid x) term)
48-
(set term (head (uuid x)))
49-
(match-destructure( term matched return l ))
50-
(set term (tail (uuid x)))
51-
(match-destructure( term matched return r ))
52-
(set term (uuid x))
53-
) (
54-
(set matched ())
55-
))
56-
) ())
57-
);
14+
#macro ('match-pats( term matched return () )) ();
15+
#macro ('match-pats( term matched return (ps (lhs rhs)) )) (
16+
# (match-pats( term matched return ps ))
17+
# (if matched () (
18+
# (set matched True)
19+
# (match-destructure( term matched return lhs ))
20+
# (if matched (
21+
# (set return rhs)
22+
# ) ())
23+
# ))
24+
#);
25+
#macro ('match-destructure( term matched return () )) (
26+
# (if matched (
27+
# (if term (
28+
# (set matched ())
29+
# ) ())
30+
# ) ())
31+
#);
32+
#macro ('match-destructure( term matched return (:Literal: l) )) (
33+
# (if matched (
34+
# (if (is-atom term) (
35+
# (if (eq( term l )) () (
36+
# (set matched ())
37+
# ))
38+
# ) (
39+
# (set matched ())
40+
# ))
41+
# ) ())
42+
#);
43+
#macro ('match-destructure( term matched return (:Variable: v) )) (
44+
# (let v term)
45+
#);
46+
#macro ('match-destructure( term matched return (l r) )) (
47+
# (if matched (
48+
# (if (is-cons term) (
49+
# (let (uuid x) term)
50+
# (set term (head (uuid x)))
51+
# (match-destructure( term matched return l ))
52+
# (set term (tail (uuid x)))
53+
# (match-destructure( term matched return r ))
54+
# (set term (uuid x))
55+
# ) (
56+
# (set matched ())
57+
# ))
58+
# ) ())
59+
#);

0 commit comments

Comments
 (0)