diff --git a/rs.rkt b/rs.rkt index c1005af..2c07a6d 100644 --- a/rs.rkt +++ b/rs.rkt @@ -110,10 +110,6 @@ ;;; A shortcut to read-context-sequence. (define-syntax-rule (read-ctx str) (read-context-sequence str)) -;;; Removes the first and the last symbol of a given string. -(define (drop-first-last str) - (substring str 1 (- (string-length str) 1))) - ;;; Converts a reaction to a triple of strings. (define/match (reaction->str-triple r) [((reaction r i p)) diff --git a/utils-tests.rkt b/utils-tests.rkt index 8bc7e46..73525bf 100644 --- a/utils-tests.rkt +++ b/utils-tests.rkt @@ -61,7 +61,10 @@ (check-equal? (hash-ref m1 '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? (read-symbol-list "a b c") '(a b c))) + (check-equal? (read-symbol-list "a b c") '(a b c)) + (check-equal? (drop-first-last "(a b)") "a b") + (check-equal? (list-sets->list-strings (list (set 'x 'y) (set 'z) (set) (set 't))) + '("y x" "z" "" "t"))) (test-case "Additional graph utilities" (let* ([gr1 (directed-graph '((a b) (b c)))] diff --git a/utils.rkt b/utils.rkt index 8031bf7..670d541 100644 --- a/utils.rkt +++ b/utils.rkt @@ -20,6 +20,8 @@ (listof (general-pair/c symbol? any/c)))] [read-org-variable-mapping (-> string? variable-mapping?)] [read-symbol-list (-> string? (listof symbol?))] + [drop-first-last (-> string? string?)] + [list-sets->list-strings (-> (listof (set/c any/c)) (listof string?))] [update-vertices/unweighted (-> graph? (-> any/c any/c) graph?)] [update-graph (->* (graph?) (#:v-func (-> any/c any/c) @@ -224,6 +226,18 @@ (define (read-symbol-list str) (string->any (string-append "(" str ")"))) +;;; 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))) + +;;; Converts a list of sets of symbols to a list of strings containing +;;; those symbols. +(define (list-sets->list-strings lst) + (map (compose drop-first-last any->string set->list) lst)) + ;;; ========================== ;;; Additional graph utilities