From 2af5656e7187bb6c5ec9bc5f22c73f5239a8484f Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Tue, 22 Dec 2020 23:10:05 +0100 Subject: [PATCH] utils: Add read-symbol-list. --- scribblings/utils.scrbl | 8 ++++++++ utils-untyped.rkt | 3 +-- utils.rkt | 10 +++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/scribblings/utils.scrbl b/scribblings/utils.scrbl index 891250e..05fe6cd 100644 --- a/scribblings/utils.scrbl +++ b/scribblings/utils.scrbl @@ -214,6 +214,14 @@ Typeset the graph via graphviz and display it. } +@defproc[(read-symbol-list (str String)) (Listof Symbol)]{ + +Reads a list of symbols from a string. + +@examples[#:eval utils-evaluator +(read-symbol-list "a b c") +]} + @section{Additional graph utilities} @section{Pretty printing} diff --git a/utils-untyped.rkt b/utils-untyped.rkt index 623dee3..98ea90f 100644 --- a/utils-untyped.rkt +++ b/utils-untyped.rkt @@ -10,8 +10,7 @@ (provide ;; Functions - (contract-out [read-symbol-list (-> string? (listof symbol?))] - [drop-first-last (-> string? string?)] + (contract-out [drop-first-last (-> string? string?)] [list-sets->list-strings (-> (listof (set/c any/c)) (listof string?))] [pretty-print-set-sets (-> (set/c (set/c symbol?) #:kind 'dont-care) string?)] [update-vertices/unweighted (-> graph? (-> any/c any/c) graph?)] diff --git a/utils.rkt b/utils.rkt index 75632f7..568aa5c 100644 --- a/utils.rkt +++ b/utils.rkt @@ -9,7 +9,7 @@ extract-symbols any->string stringify-variable-mapping string->any map-sexp read-org-sexp unorg unstringify-pairs - read-org-variable-mapping unorgv + read-org-variable-mapping unorgv read-symbol-list ;; Syntax auto-hash-ref/explicit auto-hash-ref/:) @@ -254,3 +254,11 @@ (: dotit (-> Graph Void)) (define dotit (compose display graphviz)) + +(: read-symbol-list (-> String (Listof Symbol))) +(define (read-symbol-list str) + (cast (string->any (string-append "(" str ")")) (Listof Symbol))) + +(module+ test + (test-case "read-symbol-list" + (check-equal? (read-symbol-list "a b c") '(a b c))))