File tree Expand file tree Collapse file tree 3 files changed +37
-3
lines changed
Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Original file line number Diff line number Diff line change 111111 [(PAnd p1 p2)
112112 (match (interp-match-pat p1 v r)
113113 [#f #f ]
114- [r1 (interp-match-pat p2 v r1)])]))
114+ [r1 (interp-match-pat p2 v r1)])]
115+ [(PStruct t ps)
116+ (match v
117+ [(StructVal n vs)
118+ (and (eq? t n)
119+ (interp-match-pats ps (vector->list vs) r))]
120+ [_ #f ])]))
121+
122+ ;; [Listof Pat] [Listof Val] Env -> [Maybe Env]
123+ (define (interp-match-pats ps vs r)
124+ (match ps
125+ ['() r]
126+ [(cons p ps)
127+ (match vs
128+ [(cons v vs)
129+ (match (interp-match-pat p v r)
130+ [#f #f ]
131+ [r1 (interp-match-pats ps vs r1)])])]))
115132
116133;; Id Env [Listof Defn] -> Answer
117134(define (interp-var x r ds)
Original file line number Diff line number Diff line change 11#lang racket
22(require "ast.rkt " )
3- (provide interp-prim)
3+ (provide interp-prim StructVal )
44
55;; type Struct = (StructVal Symbol (Vectorof Value))
66(struct StructVal (name vals))
Original file line number Diff line number Diff line change 108108 [(PAnd p1 p2)
109109 (match (interp-match-pat p1 v r)
110110 [#f #f ]
111- [r1 (interp-match-pat p2 v r1)])]))
111+ [r1 (interp-match-pat p2 v r1)])]
112+ [(PStruct t ps)
113+ (match v
114+ [(StructVal n vs)
115+ (and (eq? t n)
116+ (interp-match-pats ps (vector->list vs) r))]
117+ [_ #f ])]))
118+
119+ ;; [Listof Pat] [Listof Val] Env -> [Maybe Env]
120+ (define (interp-match-pats ps vs r)
121+ (match ps
122+ ['() r]
123+ [(cons p ps)
124+ (match vs
125+ [(cons v vs)
126+ (match (interp-match-pat p v r)
127+ [#f #f ]
128+ [r1 (interp-match-pats ps vs r1)])])]))
112129
113130;; Id Env [Listof Defn] -> Answer
114131(define (interp-var x r ds)
You can’t perform that action at this time.
0 commit comments