map-embeddeds

This commit is contained in:
Tony Garnock-Jones 2021-06-08 09:26:10 +02:00
parent f93d329f48
commit ade9b0a0f1
1 changed files with 20 additions and 1 deletions

View File

@ -1,5 +1,24 @@
#lang racket/base
(provide (struct-out embedded))
(provide (struct-out embedded)
map-embeddeds)
(require racket/match)
(require racket/set)
(require racket/dict)
(require "record.rkt")
(require "annotation.rkt")
(struct embedded (value) #:transparent)
(define (map-embeddeds f)
(define (walk v)
(match v
[(embedded v) (f v)]
[(annotated anns srcloc item) (annotated (map walk anns) srcloc (walk item))]
[(record label fields) (record (walk label) (map walk fields))]
[(? list? vs) (map walk vs)]
[(? set? vs) (for/set [(v (in-set vs))] (walk v))]
[(? dict? vs) (for/hash [((k v) (in-dict vs))] (values (walk k) (walk v)))]
[other other]))
walk)