File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5050;; | (PBox Pat)
5151;; | (PCons Pat Pat)
5252;; | (PAnd Pat Pat)
53+ ;; | (PSymb Symbol)
5354;; type Lit = Boolean
5455;; | Character
5556;; | Integer
7576(struct PBox (p) #:prefab )
7677(struct PCons (p1 p2) #:prefab )
7778(struct PAnd (p1 p2) #:prefab )
79+ (struct PSymb (s) #:prefab )
Original file line number Diff line number Diff line change 7979 (append (literals-e e1) (append-map literals-e es))]
8080 [(Lam f xs e)
8181 (literals-e e)]
82+ [(Match e ps es)
83+ (append (literals-e e) (append-map literals-match-clause ps es))]
84+ [_ '() ]))
85+
86+ ;; Pat Expr -> [Listof Symbol]
87+ (define (literals-match-clause p e)
88+ (append (literals-pat p) (literals-e e)))
89+
90+ ;; Pat -> [Listof Symbol]
91+ (define (literals-pat p)
92+ (match p
93+ [(PSymb s) (list s)]
94+ [(PBox p) (literals-pat p)]
95+ [(PCons p1 p2) (append (literals-pat p1) (literals-pat p2))]
96+ [(PAnd p1 p2) (append (literals-pat p1) (literals-pat p2))]
8297 [_ '() ]))
8398
8499;; Datum -> [Listof (U Symbol String)]
Original file line number Diff line number Diff line change 308308 (check-equal? (run '(string? (symbol->string 'foo ))) #t )
309309 (check-equal? (run '(eq? (symbol->string 'foo ) "foo " )) #f )
310310 (check-equal? (run ''foo ) 'foo )
311+ (check-equal? (run '(eq? (match #t [_ "foo " ]) "bar " )) #f )
312+ (check-equal? (run '(eq? (match #t [_ 'foo ]) 'bar )) #f )
311313
312314 ;; Mountebank examples
313315 (check-equal? (run '#())
Original file line number Diff line number Diff line change 4747;; | (PBox Pat)
4848;; | (PCons Pat Pat)
4949;; | (PAnd Pat Pat)
50+ ;; | (PSymb Symbol)
5051;; type Lit = Boolean
5152;; | Character
5253;; | Integer
7778(struct PBox (p) #:prefab )
7879(struct PCons (p1 p2) #:prefab )
7980(struct PAnd (p1 p2) #:prefab )
81+ (struct PSymb (s) #:prefab )
Original file line number Diff line number Diff line change 8080 (append (literals-e e1) (append-map literals-e es))]
8181 [(Lam f xs e)
8282 (literals-e e)]
83+ [(Match e ps es)
84+ (append (literals-e e) (append-map literals-match-clause ps es))]
8385 [_ '() ]))
8486
8587;; [Listof Char] -> Asm
8991 [(cons c cs)
9092 (seq (Dd (char->integer c))
9193 (compile-string-chars cs))]))
94+
95+ ;; Pat Expr -> [Listof Symbol]
96+ (define (literals-match-clause p e)
97+ (append (literals-pat p) (literals-e e)))
98+
99+ ;; Pat -> [Listof Symbol]
100+ (define (literals-pat p)
101+ (match p
102+ [(PSymb s) (list s)]
103+ [(PBox p) (literals-pat p)]
104+ [(PCons p1 p2) (append (literals-pat p1) (literals-pat p2))]
105+ [(PAnd p1 p2) (append (literals-pat p1) (literals-pat p2))]
106+ [_ '() ]))
Original file line number Diff line number Diff line change 307307 (check-equal? (run '(eq? (symbol->string 'foo ) (symbol->string 'foo ))) #f )
308308 (check-equal? (run '(string? (symbol->string 'foo ))) #t )
309309 (check-equal? (run '(eq? (symbol->string 'foo ) "foo " )) #f )
310- (check-equal? (run ''foo ) 'foo ))
310+ (check-equal? (run ''foo ) 'foo )
311+ (check-equal? (run '(eq? (match #t [_ "foo " ]) "bar " )) #f )
312+ (check-equal? (run '(eq? (match #t [_ 'foo ]) 'bar )) #f ))
311313
312314(define (test-runner-io run)
313315 ;; Evildoer examples
You can’t perform that action at this time.
0 commit comments