From 3a3c0e2d4dc7d31ca50de8bae36bd11e5f613d21 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sat, 22 Feb 2020 10:40:40 +0100 Subject: [PATCH] utils: Add sgfy. --- utils-tests.rkt | 3 +++ utils.rkt | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/utils-tests.rkt b/utils-tests.rkt index d756bd4..7ff27e5 100644 --- a/utils-tests.rkt +++ b/utils-tests.rkt @@ -39,5 +39,8 @@ (check-equal? (any->string '(a 1 (x y))) "(a 1 (x y))") (check-equal? (any->string "hello") "hello") (let ([mp (variable-mapping-stringify #hash((a . (and a b)) (b . (not b))))]) + (check-equal? (hash-ref mp 'a) "(and a b)") + (check-equal? (hash-ref mp 'b) "(not b)")) + (let ([mp (sgfy #hash((a . (and a b)) (b . (not b))))]) (check-equal? (hash-ref mp 'a) "(and a b)") (check-equal? (hash-ref mp 'b) "(not b)"))) diff --git a/utils.rkt b/utils.rkt index d83b7e2..9e73bef 100644 --- a/utils.rkt +++ b/utils.rkt @@ -17,7 +17,7 @@ (contract-out [variable-mapping? contract?] [string-variable-mapping? contract?]) ;; Syntax - auto-hash-ref/explicit auto-hash-ref/:) + auto-hash-ref/explicit auto-hash-ref/: sgfy) ;;; =================== ;;; HashTable Injection @@ -159,3 +159,6 @@ (define (variable-mapping-stringify ht) (make-hash (hash-map ht (λ (key val) (cons key (any->string val)))))) + +;;; A shortcut for variable-mapping-stingify. +(define-syntax-rule (sgfy ht) (variable-mapping-stringify ht))