utils: Type read-symbol-list.
This commit is contained in:
parent
caf9114ec5
commit
ec28541c46
2 changed files with 19 additions and 12 deletions
|
@ -218,6 +218,14 @@ produces from tables.
|
||||||
"((\"a\" . \"(and a b)\") (\"b\" . \"(or b (not a))\"))")
|
"((\"a\" . \"(and a b)\") (\"b\" . \"(or b (not a))\"))")
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
@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{Additional graph utilities}
|
||||||
@defproc[(dotit [graph Graph]) Void]{
|
@defproc[(dotit [graph Graph]) Void]{
|
||||||
|
|
||||||
|
|
23
utils.rkt
23
utils.rkt
|
@ -20,7 +20,7 @@
|
||||||
eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/:
|
eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/:
|
||||||
extract-symbols any->string stringify-variable-mapping string->any
|
extract-symbols any->string stringify-variable-mapping string->any
|
||||||
handle-org-booleans map-sexp read-org-sexp unorg unstringify-pairs
|
handle-org-booleans map-sexp read-org-sexp unorg unstringify-pairs
|
||||||
read-org-variable-mapping unorgv dotit)
|
read-org-variable-mapping unorgv read-symbol-list dotit)
|
||||||
|
|
||||||
(define-type Variable Symbol)
|
(define-type Variable Symbol)
|
||||||
(define-type (VariableMapping A) (Immutable-HashTable Variable A))
|
(define-type (VariableMapping A) (Immutable-HashTable Variable A))
|
||||||
|
@ -250,6 +250,14 @@
|
||||||
(check-equal? (hash-ref m2 'b) '(or b (not a)))
|
(check-equal? (hash-ref m2 'b) '(or b (not a)))
|
||||||
(check-equal? (hash-ref m3 'b) '(or b (not a)))))
|
(check-equal? (hash-ref m3 'b) '(or b (not a)))))
|
||||||
|
|
||||||
|
(: 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))))
|
||||||
|
|
||||||
(define dotit (compose display graphviz))
|
(define dotit (compose display graphviz))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -257,14 +265,13 @@
|
||||||
(provide eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/:
|
(provide eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/:
|
||||||
extract-symbols any->string stringify-variable-mapping string->any
|
extract-symbols any->string stringify-variable-mapping string->any
|
||||||
map-sexp read-org-sexp unorg unstringify-pairs
|
map-sexp read-org-sexp unorg unstringify-pairs
|
||||||
read-org-variable-mapping unorgv dotit)
|
read-org-variable-mapping unorgv read-symbol-list dotit)
|
||||||
|
|
||||||
;;; Untyped section.
|
;;; Untyped section.
|
||||||
|
|
||||||
(provide
|
(provide
|
||||||
;; Functions
|
;; Functions
|
||||||
(contract-out [read-symbol-list (-> string? (listof symbol?))]
|
(contract-out [drop-first-last (-> string? string?)]
|
||||||
[drop-first-last (-> string? string?)]
|
|
||||||
[list-sets->list-strings (-> (listof (set/c any/c)) (listof 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?)]
|
[pretty-print-set-sets (-> (set/c (set/c symbol?) #:kind 'dont-care) string?)]
|
||||||
[update-vertices/unweighted (-> graph? (-> any/c any/c) graph?)]
|
[update-vertices/unweighted (-> graph? (-> any/c any/c) graph?)]
|
||||||
|
@ -310,14 +317,6 @@
|
||||||
(or/c (list/c key-contract val-contract)
|
(or/c (list/c key-contract val-contract)
|
||||||
(cons/c key-contract val-contract)))
|
(cons/c key-contract val-contract)))
|
||||||
|
|
||||||
;;; Reads a list of symbols from a string.
|
|
||||||
(define (read-symbol-list str)
|
|
||||||
(string->any (string-append "(" str ")")))
|
|
||||||
|
|
||||||
(module+ test
|
|
||||||
(test-case "read-symbol-list"
|
|
||||||
(check-equal? (read-symbol-list "a b c") '(a b c))))
|
|
||||||
|
|
||||||
;;; Removes the first and the last symbol of a given string.
|
;;; Removes the first and the last symbol of a given string.
|
||||||
;;;
|
;;;
|
||||||
;;; Useful for removing the parentheses in string representations of
|
;;; Useful for removing the parentheses in string representations of
|
||||||
|
|
Loading…
Reference in a new issue