Skip to content

Commit

Permalink
Merge pull request #8 from greymd/feature/support_egison_3_6_3
Browse files Browse the repository at this point in the history
Feature/support egison 3 6 3
  • Loading branch information
greymd authored Nov 24, 2016
2 parents ab13242 + 7e7ea45 commit 565ffc0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ How to utilize it? See [examples](./doc/example.md).
## Install (Mac OSX / Linux)

### 1. Install Egison
Install *version 3.6.0*.
Install *version 3.6.3*.

Mac
http://www.egison.org/getting-started/getting-started-mac.html
Expand Down
19 changes: 13 additions & 6 deletions lib/egzact/filters.egi
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,26 @@
(let {[[$pre $pl $suf] (car (regex PHOLDER str))]}
{(foldr 2#(concat {{pre} {%1} %2 {suf}}) {} line)})))

; > (filter-crops "1.1$" {"123" "131" "222"})
; {{"131"}}
(define $filter-crops
(lambda [$str $line]
(unique/m (list string)
(extract-mached-str
(remove-empty-element
(match-all line (list string)[<join _ <join (& $x !<nil>) _>>
(regex str (S.concat x))]))))))

(extract-mached-str
(remove-empty-element
(match-all line (list string)
[<join _ <join (& $x !<nil>) _>>
(regex str (S.concat x))]))))))

; > (remove-empty-element {"11" "22" {} "1"})
; {"11" "22" "1"}
(define $remove-empty-element
(lambda [$results]
(filter 1#(not (empty? %1)) results)))

; > (extract-mached-str {{["123" "AAA" ""]} {["" "BBB" ""]}})
; {{"AAA"} {"BBB"}}
(define $extract-mached-str
(lambda [$results]
(map 1#(3#{%2} %1)
(map (lambda [$elem] (3#{%2} elem))
(map 1#(car %1) results))))
37 changes: 22 additions & 15 deletions lib/egzact/utils.egi
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
(lambda [$this-printer $this-filter $this-opts $this-arg $this-input]
(let {[[$IFS $OFS $EOR $EOS $EOF]
(set-default-opts
(opts2hash
; Avoid empty arguments.
(add "dummy=1" this-opts)))]}
(opts2hash this-opts))]}
(this-printer
this-filter
this-arg
Expand All @@ -65,11 +63,11 @@
; Set default value of each command line options.
(define $set-default-opts
(lambda [$opts] [
(set-default-value {opts_"ifs" opts_"fs" " "}) ; input field separator
(set-default-value {opts_"ofs" opts_"fs" " "}) ; output field separator
(set-default-value {opts_"eor" "\n"}) ; output row separator
(set-default-value2 {opts_"eos" "\n"}) ; output set separator
(set-default-value {opts_"eof" "\n"}) ; end of file
(set-default-value {(opts "ifs") (opts "fs") " "}) ; input field separator
(set-default-value {(opts "ofs") (opts "fs") " "}) ; output field separator
(set-default-value {(opts "eor") "\n"}) ; output row separator
(set-default-value2 {(opts "eos") "\n"}) ; output set separator
(set-default-value {(opts "eof") "\n"}) ; end of file
]))

; Infinite input stream
Expand Down Expand Up @@ -113,14 +111,23 @@
[<cons (& $x ?(string? $)) $xs> [(S.concat {"\n" x "\n"})]]
[_ [(set-default-value ls)]]})))

; Convert string collection to hash {"P1=A" "P2=B"} => {| ["P1" "A"] ["P2" "B"] |}
; Define Hash<String, String>
; Convert string collection to function which acts like key-value hash.
; {"P1=A" "P2=B"} => (match-lambda something {[,"P1" "A"] [,"P2" "B"]})
; Example:
; > (define $myhash (opts2hash {"A=B" "C=D"}))
; > (myhash "A")
; > "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
{ "(match-lambda something {"
(S.concat
(map 2#(S.concat {"[," %1 " " %2 "] "})
(map 3#[(show %1) (show %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"
Expand Down

0 comments on commit 565ffc0

Please sign in to comment.