diff --git a/lib/egzact/filters.egi b/lib/egzact/filters.egi index d213cb9..5f944c8 100644 --- a/lib/egzact/filters.egi +++ b/lib/egzact/filters.egi @@ -30,19 +30,15 @@ (lambda [$num $line] (let {[$min-num (min [num (length line)])]} (match-all line (list string) - [(loop $i [1 min-num] - > - _) - (map (1#a_%1 $) (between 1 min-num))])))) + [(loop $i [1 min-num] > _) + (map (1#a_%1 $) (between 1 min-num))])))) (define $filter-perm (lambda [$num $line] (let {[$min-num (min [num (length line)])]} (match-all line (multiset string) - [(loop $i [1 min-num] - - _) - (map (1#a_%1 $) (between 1 min-num))])))) + [(loop $i [1 min-num] _) + (map (1#a_%1 $) (between 1 min-num))])))) (define $filter-conv-each (lambda [$num $line] @@ -51,9 +47,7 @@ (define $filter-conv (lambda [$num $line] (match-all line (list string) - [ - _) > + [ _) > (map (1#a_%1 $) (between 1 num))]))) (define $filter-dupl @@ -62,12 +56,13 @@ (define $filter-flat (lambda [$num $line] - (match line (list string) { - [(loop $i [1 num] $xs) - {(map 1#a_%1 (between 1 num)) @(filter-flat num xs)}] - [>> {(append x {xs})}] - [ {}] - }))) + (match line (list string) + { + [(loop $i [1 num] $xs) + {(map 1#a_%1 (between 1 num)) @(filter-flat num xs)}] + [>> {(append x {xs})}] + [ {}] + }))) (define $filter-slit (lambda [$num $line] @@ -77,11 +72,10 @@ { [ {}] [(loop $n [1 (car part-nums)] $rest) - [(concat - {{(map (1#a_%1 $) (between 1 (car part-nums)))} - (exec-partition (cdr part-nums) rest)})]] - })) - ]} + (concat + {{(map (1#a_%1 $) (between 1 (car part-nums)))} + (exec-partition (cdr part-nums) rest)})] + }))]} (exec-partition (equalized-partition-nums (length line) num) line)))) @@ -127,17 +121,21 @@ (define $filter-takelx (lambda [$str $line] - {(match line (list string) {[) _>> - (append left {elem})] - [_ {}] ;If there is no mached patterns. - })})) + {(match line (list string) + { + [) _>> + (append left {elem})] + [_ {}] ;If there is no mached patterns. + })})) (define $filter-takerx (lambda [$str $line] - {(match line (list string) {[) _>> - (append {elem} right)] - [_ {}] ;If there is no mached patterns. - })})) + {(match line (list string) + { + [) _>> + (append {elem} right)] + [_ {}] ;If there is no mached patterns. + })})) (define $filter-dropl (lambda [$num $line] @@ -151,8 +149,10 @@ (define $filter-zrep (lambda [$str $line] - {(match line (list string) {[ ) $right>> - (concat {{elem} @(filter-zrep str right)})] + {(match line (list string) + { + [ ) $right>> + (concat {{elem} @(filter-zrep str right)})] [_ {}] ;If there is no mached patterns. })})) @@ -167,8 +167,10 @@ (define $filter-wrap-impl (lambda [$pre $suf $line] - {(match line (list string) {[ > - (concat {{(S.concat {pre elem suf})} @(filter-wrap-impl pre suf right)})] + {(match line (list string) + { + [ > + (concat {{(S.concat {pre elem suf})} @(filter-wrap-impl pre suf right)})] [_ {}] ;If there is no mached patterns. })})) diff --git a/lib/egzact/utils.egi b/lib/egzact/utils.egi index d0ed3f0..13fa9d6 100644 --- a/lib/egzact/utils.egi +++ b/lib/egzact/utils.egi @@ -23,14 +23,14 @@ [_ #f] }))) - (define $num-validation (lambda [$num] - (match {num} (list integer) { - [ [(min n ARGMAX)]] - [ [(num-validation (read n))]] - [_ ARGMAX] - }))) + (match {num} (list integer) + { + [ [(min n ARGMAX)]] + [ [(num-validation (read n))]] + [_ ARGMAX] + }))) (define $option-usage (do { @@ -49,7 +49,6 @@ (print " eos=STR End of set.") })) - (define $execution (lambda [$this-printer $this-filter $this-opts $this-arg $this-input] (let {[[$IFS $OFS $EOR $EOS $EOF] @@ -116,10 +115,12 @@ ; Convert string collection to hash {"P1=A" "P2=B"} => {| ["P1" "A"] ["P2" "B"] |} (define $opts2hash - (lambda [$args] (read (S.concat {"{| " (join-string " " - (map 3#(show [%1 %3]) - (map 1#(car (regex "=" %1)) - args))) " |}"})))) + (lambda [$args] (read (S.concat {"{| " + (join-string " " + (map 3#(show [%1 %3]) + (map 1#(car (regex "=" %1)) + args))) + " |}"})))) ; Convert two-dimensional-collection to string ; (proc "-" "@" {{"a" "b" "c"} {"d" "e" "f"} {"g"}}) => "a-b-c@d-e-f@g" @@ -131,11 +132,12 @@ ; (proc "," {"a" "b" "c"}); => "a,b,c" (define $join-string (lambda [$fs $ls] - (match ls (list string) { - [ ""] ; in case of empty element - [> lst] - [ [(S.append (S.append x fs) (join-string fs xs))]] - }))) + (match ls (list string) + { + [ ""] ; in case of empty element + [> lst] + [ [(S.append (S.append x fs) (join-string fs xs))]] + }))) ; new split-string function which can deal with empty separator (define $S.split2 @@ -147,31 +149,32 @@ ; (proc " " {"a b c" "1 2 3"}) => {"a" "b" "c" "1" "2" "3"} (define $split-whole-input (lambda [$str $line] - (match line (list string) { - [ {}] - [ - (concat {(S.split2 str x) (split-whole-input str xs)})] - }))) - + (match line (list string) + { + [ {}] + [ + (concat {(S.split2 str x) (split-whole-input str xs)})] + }))) ; (proc " " {"a b c" "1 2 3"}) => {{"a" "b" "c"} {"1" "2" "3"}} ; (proc "" {"a b c" "1 2 3"}) => {{"a" " " "b" " " "c"} {"1" " " "2" " " "3"}} (define $split-each-line (lambda [$str $line] - (match line (list string) { - [ {}] - [ - (append {(S.split2 str x)} (split-each-line str xs))] - }))) + (match line (list string) + { + [ {}] + [ + (append {(S.split2 str x)} (split-each-line str xs))] + }))) ; The behavior is same as intersperse. ; But it works even the input is infinite stream. ; (proc "---" {"a b c" "1 2 3" "e f g"}) => {"a b c" "---" "1 2 3" "---" "e f g"} (define $intersperse2 (lambda [$str $line] - (match line (list string){ - [> ;last element - {x}] - [ ;first and before last element - (append (append {x} {str}) (intersperse2 str xs))] - }))) + (match line (list string) + { + [> {x}] ;last element + [ + (append (append {x} {str}) (intersperse2 str xs))] ;first and before last element + })))