History

#t: replace with just t (or T)

Sigrid Solveig Haflínudóttir committed 1 year ago

Commit 5ab7fa91 parent 4d79d1e18 files · +151 −174Browse files

Showing the changes to test/ast (3 of 18 files). Show all

Unified · Split

3 files
  1. test/ast/asttools.lsp +38 −38
  2. test/ast/match.lsp +13 −13
  3. test/ast/rpasses.lsp +6 −6
test/ast/asttools.lsp+38−38
@@ -12,7 +12,7 @@ · 11 unmodified lines
1212 (def (index-of item lst start)
1313 (cond ((not lst) nil)
1414 ((eq? item (car lst)) start)
15− (#t (index-of item (cdr lst) (+ start 1)))))
15+ (else (index-of item (cdr lst) (+ start 1)))))
1616
1717 (def (each f l)
1818 (if (not l) l
@@ -31,15 +31,15 @@ · 12 unmodified lines
3131 (let ((new-t (map (lambda (e) (maptree-post f e)) tr)))
3232 (f new-t))))
3333
34−(def (foldtree-pre f t zero)
35− (if (not (cons? t))
36− (f t zero)
37− (foldl t (lambda (e state) (foldtree-pre f e state)) (f t zero))))
34+(def (foldtree-pre f tr zero)
35+ (if (not (cons? tr))
36+ (f tr zero)
37+ (foldl tr (lambda (e state) (foldtree-pre f e state)) (f tr zero))))
3838
39−(def (foldtree-post f t zero)
40− (if (not (cons? t))
41− (f t zero)
42− (f t (foldl t (lambda (e state) (foldtree-post f e state)) zero))))
39+(def (foldtree-post f tr zero)
40+ (if (not (cons? tr))
41+ (f tr zero)
42+ (f tr (foldl tr (lambda (e state) (foldtree-post f e state)) zero))))
4343
4444 ; general tree transformer
4545 ; folds in preorder (foldtree-pre), maps in postorder (maptree-post)
@@ -48,39 +48,39 @@ · 2 unmodified lines
4848 ; approach.
4949 ; (mapper tree state) - should return transformed tree given current state
5050 ; (folder tree state) - should return new state
51−(def (map&fold t zero mapper folder)
52− (let ((head (and (cons? t) (car t))))
53− (cond ((eq? head 'quote)
54− t)
51+(def (map&fold tr zero mapper folder)
52+ (let ((head (and (cons? tr) (car tr))))
53+ (cond
54+ ((eq? head 'quote) tr)
5555 ((or (eq? head 'the) (eq? head 'meta))
5656 (list head
57− (cadr t)
58− (map&fold (caddr t) zero mapper folder)))
57+ (cadr tr)
58+ (map&fold (caddr tr) zero mapper folder)))
5959 (else
60− (let ((new-s (folder t zero)))
60+ (let ((new-s (folder tr zero)))
6161 (mapper
62− (if (cons? t)
62+ (if (cons? tr)
6363 ; head symbol is a tag; never transform it
64− (cons (car t)
64+ (cons (car tr)
6565 (map (lambda (e) (map&fold e new-s mapper folder))
66− (cdr t)))
67− t)
66+ (cdr tr)))
67+ tr)
6868 new-s))))))
6969
7070 ; convert to proper list, i.e. remove "dots", and append
7171 (def (append.2 l tail)
72− (cond ((not l) tail)
72+ (cond ((not l) tail)
7373 ((atom? l) (cons l tail))
74− (#t (cons (car l) (append.2 (cdr l) tail)))))
74+ (else (cons (car l) (append.2 (cdr l) tail)))))
7575
7676 ; transform code by calling (f expr env) on each subexpr, where
7777 ; env is a list of lexical variables in effect at that point.
78−(def (lexical-walk f t)
79− (map&fold t () f
78+(def (lexical-walk f tr)
79+ (map&fold tr () f
8080 (lambda (tree state)
81− (if (and (eq? (car t) 'lambda)
82− (cons? (cdr t)))
83− (append.2 (cadr t) state)
81+ (if (and (eq? (car tr) 'lambda)
82+ (cons? (cdr tr)))
83+ (append.2 (cadr tr) state)
8484 state))))
8585
8686 ; collapse forms like (&& (&& (&& (&& a b) c) d) e) to (&& a b c d e)
@@ -118,7 +118,7 @@ · 31 unmodified lines
118118 (map (lambda (se) (lvc- se newenv))
119119 (cddr e))))
120120 (map (lambda (se) (lvc- se env)) e)))))
121− (#t e)))
121+ (else e)))
122122 (def (lexical-var-conversion e)
123123 (lvc- e ()))
124124
@@ -137,19 +137,19 @@ · 12 unmodified lines
137137 (map&fold e
138138 ()
139139 ; mapper: replace symbol if unbound
140− (lambda (t env)
141− (if (symbol? t)
142− (let ((found (assq t transl)))
140+ (lambda (te env)
141+ (if (symbol? te)
142+ (let ((found (assq te transl)))
143143 (if (and found
144− (not (memq t env)))
144+ (not (memq te env)))
145145 (cdr found)
146− t))
147− t))
146+ te))
147+ te))
148148 ; folder: add locals to environment if entering a new scope
149− (lambda (t env)
150− (if (and (cons? t) (or (eq? (car t) 'let)
151− (eq? (car t) 'lambda)))
152− (append (cadr t) env)
149+ (lambda (te env)
150+ (if (and (cons? te) (or (eq? (car te) 'let)
151+ (eq? (car te) 'lambda)))
152+ (append (cadr te) env)
153153 env))))
154154
155155 ; flatten op with any associativity
test/ast/match.lsp+13−13
@@ -4,7 +4,7 @@ · 3 unmodified lines
44
55 (def (unique lst)
66 (if (not lst)
7− ()
7+ nil
88 (cons (car lst)
99 (filter (lambda (x) (not (eq? x (car lst))))
1010 (unique (cdr lst))))))
@@ -20,7 +20,7 @@ · 9 unmodified lines
2020 ; p is an expression in the following pattern language:
2121 ;
2222 ; _ match anything, not captured
23−; <func> any scheme function; matches if (func expr) returns #t
23+; <func> any scheme function; matches if (func expr) returns T
2424 ; <var> match anything and capture as <var>. future occurrences of <var> in the pattern
2525 ; must match the same thing.
2626 ; (head <p1> <p2> etc) match an s-expr with 'head' matched literally, and the rest of the
@@ -41,7 +41,7 @@ · 14 unmodified lines
4141 (def (match- p expr state)
4242 (cond ((symbol? p)
4343 (cond ((eq? p '_) state)
44− (#t
44+ (else
4545 (let ((capt (assq p state)))
4646 (if capt
4747 (and (equal? expr (cdr capt)) state)
@@ -57,13 +57,13 @@ · 9 unmodified lines
5757 (and (match- (caddr p) expr state)
5858 (cons (cons (cadr p) expr) state)))
5959 ((eq? (car p) '-$) ; greedy alternation for toplevel pattern
60− (match-alt (cdr p) () (list expr) state nil 1))
61− (#t
60+ (match-alt (cdr p) nil (list expr) state nil 1))
61+ (else
6262 (and (cons? expr)
6363 (equal? (car p) (car expr))
6464 (match-seq (cdr p) (cdr expr) state (length (cdr expr)))))))
6565
66− (#t
66+ (else
6767 (and (equal? p expr) state))))
6868
6969 ; match an alternation
@@ -95,17 +95,17 @@ · 25 unmodified lines
9595 (match-star- p prest (cdr expr) state var (- min 1) (- max 1) (- L 1)
9696 (cons (car expr) sofar))))
9797 ; otherwise, must match either 0 or between 1 and max subexpressions
98− (#t
98+ (else
9999 (or (match-star- p prest expr state var 0 0 L sofar)
100100 (match-star- p prest expr state var 1 max L sofar)))))
101101 (def (match-star p prest expr state var min max L)
102− (match-star- p prest expr state var min max L ()))
102+ (match-star- p prest expr state var min max L nil))
103103
104104 ; match sequences of expressions
105105 (def (match-seq p expr state L)
106106 (cond ((not state) nil)
107107 ((not p) (if (not expr) state nil))
108− (#t
108+ (else
109109 (let ((subp (car p))
110110 (var nil))
111111 (if (and (cons? subp)
@@ -113,7 +113,7 @@ · 1 unmodified line
113113 (begin (set! var (cadr subp))
114114 (set! subp (caddr subp)))
115115 nil)
116− (let ((head (if (cons? subp) (car subp) ())))
116+ (let ((head (if (cons? subp) (car subp) nil)))
117117 (cond ((eq? subp '...)
118118 (match-star '_ (cdr p) expr state var 0 L L))
119119 ((eq? head '-*)
@@ -124,7 +124,7 @@ · 4 unmodified lines
124124 (match-star (cadr subp) (cdr p) expr state var 0 1 L))
125125 ((eq? head '-$)
126126 (match-alt (cdr subp) (cdr p) expr state var L))
127− (#t
127+ (else
128128 (and (cons? expr)
129129 (match-seq (cdr p) (cdr expr)
130130 (match- (car p) (car expr) state)
@@ -140,10 +140,10 @@ · 9 unmodified lines
140140
141141 ((cons? p)
142142 (if (eq? (car p) '-/)
143− ()
143+ nil
144144 (unique (apply append (map patargs- (cdr p))))))
145145
146− (#t ())))
146+ (else nil)))
147147 (def (patargs p)
148148 (cons '__ (patargs- p)))
149149
test/ast/rpasses.lsp+6−6
@@ -14,7 +14,7 @@ · 13 unmodified lines
1414
1515 (def (func-argnames f)
1616 (let ((argl (cadr f)))
17− (if (eq? argl '*r-null*) ()
17+ (if (eq? argl '*r-null*) nil
1818 (map cadr argl))))
1919
2020 ; transformations
@@ -49,7 +49,7 @@ · 28 unmodified lines
4949 (<<- (r-call f lhs ...) rhs))
5050 (let ((g (if (cons? rhs) (r-gensym) rhs))
5151 (op (car __)))
52− `(r-block ,@(if (cons? rhs) `((ref= ,g ,rhs)) ())
52+ `(r-block ,@(if (cons? rhs) `((ref= ,g ,rhs)) nil)
5353 (,op ,lhs (r-call ,(symconcat f '<-) ,@(cddr (cadr __)) ,g))
5454 ,g)))
5555 e))
@@ -80,14 +80,14 @@ · 24 unmodified lines
8080 e))
8181
8282 (def (find-assigned-vars n)
83− (let ((vars ()))
83+ (let ((vars nil))
8484 (maptree-pre (lambda (s)
8585 (if (not (cons? s)) s
86− (cond ((eq? (car s) 'lambda) ())
86+ (cond ((eq? (car s) 'lambda) nil)
8787 ((eq? (car s) '<-)
8888 (set! vars (list-adjoin (cadr s) vars))
8989 (cddr s))
90− (#t s))))
90+ (else s))))
9191 n)
9292 vars))
9393
@@ -96,7 +96,7 @@ · 2 unmodified lines
9696 (maptree-post (lambda (n)
9797 (if (and (cons? n) (eq? (car n) 'lambda))
9898 (let ((vars (find-assigned-vars (cddr n))))
99− `(lambda ,(cadr n) (let ,(map (lambda (v) (list v ()))
99+ `(lambda ,(cadr n) (let ,(map (lambda (v) (list v nil))
100100 vars)
101101 ,@(cddr n))))
102102 n))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t