diff --git a/scribblings/utils.scrbl b/scribblings/utils.scrbl index 05fe6cd..fcb036e 100644 --- a/scribblings/utils.scrbl +++ b/scribblings/utils.scrbl @@ -222,6 +222,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} @section{Pretty printing} diff --git a/utils-untyped.rkt b/utils-untyped.rkt index 98ea90f..0b75df9 100644 --- a/utils-untyped.rkt +++ b/utils-untyped.rkt @@ -10,8 +10,7 @@ (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?) diff --git a/utils.rkt b/utils.rkt index 568aa5c..e31554d 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-symbol-list + read-org-variable-mapping unorgv read-symbol-list drop-first-last ;; Syntax auto-hash-ref/explicit auto-hash-ref/:) @@ -262,3 +262,11 @@ (module+ test (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")))