aboutsummaryrefslogtreecommitdiff
path: root/lib.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'lib.rkt')
-rw-r--r--lib.rkt39
1 files changed, 38 insertions, 1 deletions
diff --git a/lib.rkt b/lib.rkt
index 85ea0ce..c0e1e3e 100644
--- a/lib.rkt
+++ b/lib.rkt
@@ -19,6 +19,9 @@
msg)))
(define-syntax-rule (note msg)
+ (eprintf "note: ~a~%" msg))
+
+(define-syntax-rule (print msg)
(eprintf "~a~%" msg))
(define-syntax (todo stx)
@@ -29,5 +32,39 @@
; todo: write a fmt alias to format
; todo: write a namer
-(provide dbg err note todo)
+;; removes typing annotations
+(define (strip expr)
+ (match expr
+ [`(λ ,id (: ,type) ,body (: ,type)) `(λ ,(strip id) ,(strip body))]
+ [`(λ ,id ,body (: ,type)) `(λ ,(strip id) ,(strip body))]
+ [`(λ ,id (: ,type) ,body) `(λ ,(strip id) ,(strip body))]
+ [`(,a ,b) `(,(strip a) ,(strip b))]
+ [expr expr]))
+
+;; (fmt Expr) → String
+(define (fmt expr)
+ (match expr
+ ['sole "⟨⟩"]
+ [`(λ ,id ,body) (format "λ~a.[~a]" id (fmt body))]
+ [`((λ ,id ,body) ,arg) (format "~a = ~a; ~a" id (fmt arg) (fmt body))]
+ [`(λ ,id (: ,type) ,body) (format "~a: ~a; ~a" id (fmt type) (fmt body))]
+ [`((λ ,id (: ,type) ,body) ,arg) (format "~a: ~a; ~a = ~a; ~a" id (fmt type) id (fmt arg) (fmt body))]
+ [`(λ ,id ,body ,env) (format "λ~a.[~a]" id (fmt body))]
+ [`(let ,id ,expr ,body) (format "~a = ~a; ~a" id (fmt expr) (fmt body))]
+ [`(let ,id (: ,type) ,expr ,body) (format "~a: ~a; ~a = ~a; ~a" id (fmt type) id (fmt expr) (fmt body))]
+ [`(set ,id ,expr ,body) (format "~a := ~a; ~a" id (fmt expr) (fmt body))]
+ [`(→ ,a ,b) (format "(~a → ~a)" (fmt a) (fmt b))]
+ [`(→ ,k ,a ,b) (format "(~a →~a ~a)" (fmt a) k (fmt b))]
+ [`(Ref ,a) (format "Ref ~a" (fmt a))]
+ [`(new ,a) (format "new ~a" (fmt a))]
+ [`(! ,a) (format "!~a" (fmt a))]
+ [`(,a ,b) (format "(~a ~a)" (fmt a) (fmt b))]
+ [(hash-table) "{}"] ; fixme lmao
+ [(hash-table (k v)) (format "{~a: ~a}" (fmt k) (fmt v))]
+ [(hash-table (k1 v1) (k2 v2)) (format "{~a: ~a; ~a: ~a}" (fmt k1) (fmt v1) (fmt k2) (fmt v2))]
+ [(hash-table (k1 v1) (k2 v2) (k3 v3)) (format "{~a: ~a; ~a: ~a; ~a: ~a}" (fmt k1) (fmt v1) (fmt k2) (fmt v2) (fmt k3) (fmt v3))]
+ [expr (format "~a" expr)]))
+
+
+(provide dbg err note print todo strip fmt)
; todo: how to provide everything??