utils: Type drop-first-last.
This commit is contained in:
parent
ec28541c46
commit
403401f085
2 changed files with 23 additions and 15 deletions
|
@ -226,6 +226,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}
|
||||||
@defproc[(dotit [graph Graph]) Void]{
|
@defproc[(dotit [graph Graph]) Void]{
|
||||||
|
|
||||||
|
|
28
utils.rkt
28
utils.rkt
|
@ -20,7 +20,8 @@
|
||||||
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 read-symbol-list dotit)
|
read-org-variable-mapping unorgv read-symbol-list drop-first-last
|
||||||
|
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))
|
||||||
|
@ -258,6 +259,14 @@
|
||||||
(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")))
|
||||||
|
|
||||||
(define dotit (compose display graphviz))
|
(define dotit (compose display graphviz))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -265,14 +274,14 @@
|
||||||
(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 read-symbol-list dotit)
|
read-org-variable-mapping unorgv read-symbol-list drop-first-last
|
||||||
|
dotit)
|
||||||
|
|
||||||
;;; Untyped section.
|
;;; Untyped section.
|
||||||
|
|
||||||
(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?)
|
||||||
|
@ -317,17 +326,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)))
|
||||||
|
|
||||||
;;; 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
|
;;; Converts a list of sets of symbols to a list of strings containing
|
||||||
;;; those symbols.
|
;;; those symbols.
|
||||||
(define (list-sets->list-strings lst)
|
(define (list-sets->list-strings lst)
|
||||||
|
|
Loading…
Reference in a new issue