From 3a4704b8fce33f3d86897ff857d59462b93a6755 Mon Sep 17 00:00:00 2001 From: JJ Date: Sun, 16 Jun 2024 17:16:51 -0700 Subject: stlc-ext: add primitive operations on booleans and naturals --- stlc-ext.rkt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'stlc-ext.rkt') diff --git a/stlc-ext.rkt b/stlc-ext.rkt index 0bc69b5..80ff6d9 100644 --- a/stlc-ext.rkt +++ b/stlc-ext.rkt @@ -15,6 +15,16 @@ [b #:when (boolean? b) b] [x #:when (dict-has-key? ctx x) (dict-ref ctx x)] + [`(inc ,e) + (match (interpret- e ctx heap) + [n #:when (natural? n) (+ n 1)] + [e (format "incrementing an unknown value ~a" e)])] + [`(if ,c ,e1 ,e2) + (match (interpret- c ctx heap) + ['#t (interpret- e1 ctx heap)] + ['#f (interpret- e2 ctx heap)] + [e (err (format "calling if on unknown expression ~a" e))])] + [`(pair ,e1 ,e2) `(pair ,(interpret- e1 ctx) ,(interpret- e2 ctx))] [`(car ,e) @@ -64,7 +74,6 @@ (define (check expr with [Γ #hash()]) (check- (desugar expr) with Γ)) (define (check- expr with Γ) - ; (print (format "check: ~a" (fmt expr))) (let ([with (if (dict-has-key? Γ with) (dict-ref Γ with) with)]) (match* (expr with) [('sole 'Unit) #t] -- cgit v1.2.3-70-g09d2