;;;;; ;;;;; ;;;;; S.ring ;;;;; ;;;;; (define $string (matcher {[ [string (list string) string] {[$tgt (regex-cg regexpr tgt)]}] [ [string string string] {[$tgt (regex regexpr tgt)]}] [ [] {[$tgt (if (eq? "" tgt) {[]} {})]}] [ [char string] {[$tgt (if (eq? "" tgt) {} {(uncons-string tgt)})]}] [> [string string] {[$tgt (match-all (S.split (pack {px}) tgt) (list string) [ $xs) (& ! $ys)> [(S.intercalate (pack {px}) xs) (S.intercalate (pack {px}) ys) ]])]}] [> [string string] {[$tgt (match-all (S.split pxs tgt) (list string) [ $xs) (& ! $ys)> [(S.intercalate pxs xs) (S.intercalate pxs ys) ]])]}] [ [string string] {[$tgt (match-all tgt string [(loop $i [1 $n] $rs) [(pack (map (lambda [$i] xa_i) (between 1 n))) rs]])]}] [,$val [] {[$tgt (if (eq? val tgt) {[]} {})]}] [$ [something] {[$tgt {tgt}]}] })) ;;; ;;; S.ring as collection ;;; (define $S.empty? (lambda [$xs] (eq? xs ""))) (define $S.cons (lambda [$x $xs] (append-string (pack {x}) xs))) (define $S.car (lambda [$xs] (match xs string {[ x]}))) (define $S.cdr (lambda [$xs] (match xs string {[ r]}))) (define $S.rac (lambda [$str] (match str string {[>> c]}))) (define $S.map (lambda [$f $xs] (pack (map f (unpack xs))))) (define $S.length (lambda [$xs] (length-string xs))) (define $S.split (lambda [$in $ls] (split-string in ls))) (define $S.append (lambda [$xs $ys] (append-string xs ys))) (define $S.concat (lambda [$xss] (foldr (lambda [$xs $rs] (S.append xs rs)) "" xss))) (define $S.intercalate (compose intersperse S.concat)) (define $S.replace (lambda [$before $after $str] (S.intercalate after (S.split before str)))) ;; ;; Alphabet ;; (define $c.between (lambda [$c1 $c2] (map itoc (between (ctoi c1) (ctoi c2))))) (define $c.between? (lambda [$c1 $c2 $c] (and (gte? (ctoi c) (ctoi c1)) (lte? (ctoi c) (ctoi c2))))) (define $alphabet? (lambda [$c] (or (c.between? c#a c#z c) (c.between? c#A c#Z c)))) (define $alphabets? (lambda [$s] (all alphabet? (unpack s)))) (define $upper-case (lambda [$c] (if (c.between? c#a c#z c) (itoc (- (ctoi c) 32)) c))) (define $lower-case (lambda [$c] (if (c.between? c#A c#Z c) (itoc (+ (ctoi c) 32)) c)))