utils: Add drop-first-last.

This commit is contained in:
Sergiu Ivanov 2020-12-23 11:02:00 +01:00
parent 2af5656e71
commit de80275a47
3 changed files with 20 additions and 3 deletions

View file

@ -222,6 +222,16 @@ Reads a list of symbols from a string.
(read-symbol-list "a b c") (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{Additional graph utilities}
@section{Pretty printing} @section{Pretty printing}

View file

@ -10,8 +10,7 @@
(provide (provide
;; Functions ;; Functions
(contract-out [drop-first-last (-> string? string?)] (contract-out [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?)]
[update-graph (->* (graph?) [update-graph (->* (graph?)

View file

@ -9,7 +9,7 @@
extract-symbols extract-symbols
any->string stringify-variable-mapping string->any map-sexp any->string stringify-variable-mapping string->any map-sexp
read-org-sexp unorg unstringify-pairs 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 ;; Syntax
auto-hash-ref/explicit auto-hash-ref/:) auto-hash-ref/explicit auto-hash-ref/:)
@ -262,3 +262,11 @@
(module+ test (module+ test
(test-case "read-symbol-list" (test-case "read-symbol-list"
(check-equal? (read-symbol-list "a b c") '(a b c)))) (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")))