-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat.shen
71 lines (56 loc) · 1.73 KB
/
format.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
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
(define dict->'
D K V -> (do (dict-> D K V) D))
(define @d-macro-h
N [] -> [dict N]
N [K V | KVs] -> [dict->' (@d-macro-h N KVs) K V])
(defmacro @d-macro
[@d | KVs] ->
(if (= 0 (shen.mod (length KVs) 2))
(@d-macro-h (/ (length KVs) 2) KVs)
(error "@d macro requires even number of arguments")))
\\ {number --> list A --> list A}
(define take
0 _ -> []
_ [] -> []
N [X | Xs] -> [X | (take (- N 1) Xs)])
(define take-until-h
_ Ys [] -> [(reverse Ys) | []]
F Ys [X | Xs] -> [(reverse Ys) | [X | Xs]] where (F X)
F Ys [X | Xs] -> (take-until-h [X | Ys] Xs))
\\ {(A --> boolean) --> list A --> list A --> list (list A)}
(define take-until
F Xs -> (take-until-h F [] Xs))
(define take-until+-h
_ Ys [] -> [(reverse Ys) | []]
F Ys [X | Xs] -> [(reverse [X | Ys]) | Xs] where (F X)
F Ys [X | Xs] -> (take-until+-h [X | Ys] Xs))
\\ {(A --> boolean) --> list A --> list A --> list (list A)}
(define take-until+
F Xs -> (take-until+-h F [] Xs))
\\ {list A --> number}
(define clause-arity
Xs -> (length (take-until (= ->) Xs)))
(define take-clause
ArgCount Xs -> )
(define group-clauses
_ [] -> []
N Clauses -> (append (group-clauses N )))
(define strlen-h
N "" -> N
N (@s _ S) -> (strlen-h (+ 1 N) S))
\\ {string --> number}
(define strlen
Str -> (strlen-h 0 Str))
(define parse-expression
[define Name { | Body] ->
(let Split (take-until+ (= }) [] [{ | Body])
(@d name Name typesig (hd Split) clauses (tl Body)))
[define Name | Body] -> (@d name Name clauses Body))
(define format-expression
[define Name | Body] -> []
[defmacro Name | Body] -> []
[defprolog Name | Body] -> []
[defcc Name | Body] -> []
[datatype | Body] -> []
[package Name Exports | Body] -> []
Expr -> Expr)