From 1273a9595f80014b6493fdff6ffe39afc3d94fdf Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sat, 5 Dec 2020 00:22:49 +0100 Subject: [PATCH] utils.rkt: Copy stringify-variable-mapping. --- scribblings/utils.scrbl | 10 +++++++++- utils-untyped.rkt | 3 +-- utils.rkt | 13 ++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/scribblings/utils.scrbl b/scribblings/utils.scrbl index 2a0fdda..162d7c2 100644 --- a/scribblings/utils.scrbl +++ b/scribblings/utils.scrbl @@ -2,7 +2,7 @@ @(require scribble/example racket/sandbox (for-label racket graph "../utils.rkt" (only-in typed/racket/base - Any AnyValues Listof))) + Any AnyValues Listof String))) @title[#:tag "utils"]{dds/utils: Various Utilities} @@ -139,6 +139,14 @@ the result in a string. (any->string '(a 1 (x y))) ]} +@defproc[(stringify-variable-mapping [ht (VariableMapping Any)]) (VariableMapping String)]{ + +Converts all the values of a @racket[VariableMapping] to string. + +@examples[#:eval utils-evaluator +(stringify-variable-mapping (hash 'a '(and a b) 'b '(not b))) +]} + @section{Additional graph utilities} @section{Pretty printing} diff --git a/utils-untyped.rkt b/utils-untyped.rkt index c748a4e..5382214 100644 --- a/utils-untyped.rkt +++ b/utils-untyped.rkt @@ -10,8 +10,7 @@ (provide ;; Functions - (contract-out [stringify-variable-mapping (-> variable-mapping? string-variable-mapping?)] - [string->any (-> string? any/c)] + (contract-out [string->any (-> string? any/c)] [read-org-sexp (-> string? (listof any/c))] [map-sexp (-> procedure? any/c any/c)] [unorg (-> string? (listof any/c))] diff --git a/utils.rkt b/utils.rkt index 04088c0..be90701 100644 --- a/utils.rkt +++ b/utils.rkt @@ -5,7 +5,7 @@ (provide Symbol VariableMapping eval-with eval1-with extract-symbols - any->string + any->string stringify-variable-mapping ;; Syntax auto-hash-ref/explicit auto-hash-ref/:) @@ -140,3 +140,14 @@ (check-equal? (any->string 'a) "a") (check-equal? (any->string '(a 1 (x y))) "(a 1 (x y))") (check-equal? (any->string "hello") "hello"))) + +(: stringify-variable-mapping (-> (VariableMapping Any) (VariableMapping String))) +(define (stringify-variable-mapping ht) + (for/hash : (VariableMapping String) + ([(key val) (in-hash ht)]) (values key (any->string val)))) + +(module+ test + (test-case "stringify-variable-mapping" + (define mp (stringify-variable-mapping #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)")))