utils.rkt: Copy any->string.

This commit is contained in:
Sergiu Ivanov 2020-12-04 23:43:53 +01:00
parent 9e65f07ce0
commit c9d36ea45e
3 changed files with 26 additions and 2 deletions

View file

@ -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}

View file

@ -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)]

View file

@ -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")))