diff --git a/scribblings/utils.scrbl b/scribblings/utils.scrbl index 7e49fdc..66e7f91 100644 --- a/scribblings/utils.scrbl +++ b/scribblings/utils.scrbl @@ -226,6 +226,16 @@ Reads a list of symbols from a string. (read-symbol-list "a b c") ]} +@defproc[(drop-first-last (str String)) String]{ + +Removes the first and the last symbol of a given string. + +Useful for removing the parentheses in string representations of lists. + +@examples[#:eval utils-evaluator +(drop-first-last "(a b)") +]} + @section{Additional graph utilities} @defproc[(dotit [graph Graph]) Void]{ diff --git a/utils.rkt b/utils.rkt index a09b29a..6ed1824 100644 --- a/utils.rkt +++ b/utils.rkt @@ -20,7 +20,8 @@ eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/: extract-symbols any->string stringify-variable-mapping string->any handle-org-booleans map-sexp read-org-sexp unorg unstringify-pairs - read-org-variable-mapping unorgv read-symbol-list dotit) + read-org-variable-mapping unorgv read-symbol-list drop-first-last + dotit) (define-type Variable Symbol) (define-type (VariableMapping A) (Immutable-HashTable Variable A)) @@ -258,6 +259,14 @@ (test-case "read-symbol-list" (check-equal? (read-symbol-list "a b c") '(a b c)))) + (: drop-first-last (-> String String)) + (define (drop-first-last str) + (substring str 1 (- (string-length str) 1))) + + (module+ test + (test-case "drop-first-last" + (check-equal? (drop-first-last "(a b)") "a b"))) + (define dotit (compose display graphviz)) ) @@ -265,14 +274,14 @@ (provide eval-with eval1-with auto-hash-ref/explicit auto-hash-ref/: extract-symbols any->string stringify-variable-mapping string->any map-sexp read-org-sexp unorg unstringify-pairs - read-org-variable-mapping unorgv read-symbol-list dotit) + read-org-variable-mapping unorgv read-symbol-list drop-first-last + dotit) ;;; Untyped section. (provide ;; Functions - (contract-out [drop-first-last (-> string? string?)] - [list-sets->list-strings (-> (listof (set/c any/c)) (listof string?))] + (contract-out [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?)] [update-graph (->* (graph?) @@ -317,17 +326,6 @@ (or/c (list/c key-contract val-contract) (cons/c key-contract val-contract))) -;;; Removes the first and the last symbol of a given string. -;;; -;;; Useful for removing the parentheses in string representations of -;;; lists. -(define (drop-first-last str) - (substring str 1 (- (string-length str) 1))) - -(module+ test - (test-case "drop-first-last" - (check-equal? (drop-first-last "(a b)") "a b"))) - ;;; Converts a list of sets of symbols to a list of strings containing ;;; those symbols. (define (list-sets->list-strings lst)