28 lines
776 B
Racket
28 lines
776 B
Racket
|
#lang typed/racket
|
||
|
|
||
|
;;; dds/utils
|
||
|
|
||
|
;;; Various utilities.
|
||
|
|
||
|
(require (for-syntax syntax/parse))
|
||
|
|
||
|
(provide auto-hash-ref/explicit)
|
||
|
|
||
|
;;; HashTable Injection
|
||
|
|
||
|
;;; This section of the file contains some utilities to streamline the
|
||
|
;;; usage of hash tables mapping symbols to values. The goal is
|
||
|
;;; essentially to avoid having to write explicit hash-ref calls.
|
||
|
|
||
|
;;; Given a (HashTable Symbol a) and a sequence of symbols, binds
|
||
|
;;; these symbols to the values they are associated to in the hash
|
||
|
;;; table, then puts the body in the context of these bindings.
|
||
|
(define-syntax (auto-hash-ref/explicit stx)
|
||
|
(syntax-parse stx
|
||
|
[(_ (ht:id xs:id ...) body:expr)
|
||
|
#`(let #,(for/list ([x (syntax->list #'(xs ...))])
|
||
|
#`[#,x (hash-ref ht '#,x)])
|
||
|
body)]))
|
||
|
|
||
|
|