diff --git a/scribblings/utils.scrbl b/scribblings/utils.scrbl index 706b919..2a0fdda 100644 --- a/scribblings/utils.scrbl +++ b/scribblings/utils.scrbl @@ -130,6 +130,15 @@ See @hyperlink["https://git.marvid.fr/scolobb/dds/src/branch/master/example/example.org"]{example.org} for examples of usage. +@defproc[(any->string [x Any]) String]{ + +Converts any value to string by calling @racket[display] on it and capturing +the result in a string. + +@examples[#:eval utils-evaluator +(any->string '(a 1 (x y))) +]} + @section{Additional graph utilities} @section{Pretty printing} diff --git a/utils-untyped.rkt b/utils-untyped.rkt index a3f8857..c748a4e 100644 --- a/utils-untyped.rkt +++ b/utils-untyped.rkt @@ -10,8 +10,7 @@ (provide ;; Functions - (contract-out [any->string (-> any/c string?)] - [stringify-variable-mapping (-> variable-mapping? string-variable-mapping?)] + (contract-out [stringify-variable-mapping (-> variable-mapping? string-variable-mapping?)] [string->any (-> string? any/c)] [read-org-sexp (-> string? (listof any/c))] [map-sexp (-> procedure? any/c any/c)] diff --git a/utils.rkt b/utils.rkt index ef1b1dd..04088c0 100644 --- a/utils.rkt +++ b/utils.rkt @@ -5,6 +5,7 @@ (provide Symbol VariableMapping eval-with eval1-with extract-symbols + any->string ;; Syntax auto-hash-ref/explicit auto-hash-ref/:) @@ -124,3 +125,18 @@ (test-case "extract-symbols" (check-equal? (extract-symbols '(1 (2 3) x (y z 3))) '(x y z)))) + + +;;; ========================= +;;; Org-mode interoperability +;;; ========================= + +(: any->string (-> Any String)) +(define (any->string x) + (with-output-to-string (λ () (display x)))) + +(module+ test + (test-case "any->string" + (check-equal? (any->string 'a) "a") + (check-equal? (any->string '(a 1 (x y))) "(a 1 (x y))") + (check-equal? (any->string "hello") "hello")))