Use define-syntax-parser in auto-hash-ref/explicit.

This commit is contained in:
Sergiu Ivanov 2022-03-31 23:40:12 +02:00
parent b07cda477f
commit 5aa816507d

View file

@ -1,6 +1,6 @@
#lang typed/racket
(require typed/graph typed-compose typed/racket/stream
(require typed/graph typed-compose typed/racket/stream syntax/parse/define
(for-syntax syntax/parse racket/list))
(provide
@ -45,12 +45,11 @@
(check-equal? (eval1-with ht expr)
4)))
(define-syntax (auto-hash-ref/explicit stx)
(syntax-parse stx
[(_ (ht:id keys:id ...) body:expr)
#`(let #,(for/list ([key (syntax->list #'(keys ...))])
`[,key (hash-ref ,#'ht ',key)])
body)]))
(define-syntax-parser auto-hash-ref/explicit
[(_ (ht:id keys:id ...) body:expr)
#`(let #,(for/list ([key (syntax->list #'(keys ...))])
`[,key (hash-ref ,#'ht ',key)])
body)])
(module+ test
(test-case "auto-hash-ref/explicit"