:- :~ navhome/'/docs/' sort/'13' title/'2j: Jar and Jug Logic' == ;> # 2j: jar and jug logic ### `++ja` Jar engine ``` |_ a=(jar) ``` A container arm for `++jar` operation arms. A `++jar` is a `++map` of `++list`s. The contained arms inherit the sample jar. `a` is a jar. ``` > ~(. ja (mo (limo a/"ho" b/"he" ~))) <2.dgz [nlr([p={%a %b} q=""]) <414.fvk 101.jzo 1.ypj %164>]> ``` --- ### `+-get:ja` Grab value by key ``` +- get :: gets list by key |* b=* =+ c=(~(get by a) b) ?~(c ~ u.c) ``` #### Accepts `a` is a `++jar`. `b` is a key of the same type as the keys in `a`. #### Produces A list retrieved from jar `a` using the key `b`. Examples ``` > =l (mo `(list ,[@t (list ,@)])`[['a' `(list ,@)`[1 2 3 ~]] ['b' `(list ,@)`[4 5 6 ~]] ~]) > l [[p='a' q=~[1 2 3]] [p='b' q=~[4 5 6]]} > (~(get ja l) 'a') ~[1 2 3] > (~(get ja l) 'b') ~[4 5 6] > (~(get ja l) 'c') ~ ``` --- ### `+-add:ja` Prepend to list #### Source ``` +- add :: adds key-list pair |* [b=* c=*] =+ d=(get b) (~(put by a) b [c d]) ``` #### Accepts `a` is a jar. `b` is a key of the same type as the keys in `a`. `c` is a value of the same type as the values in `a`. #### Examples ``` > =l (mo `(list ,[@t (list ,@)])`[['a' `(list ,@)`[1 2 3 ~]] ['b' `(list ,@)`[4 5 6 ~]] ~]) > l {[p='a' q=~[1 2 3]] [p='b' q=~[4 5 6]]} > (~(add ja l) 'b' 7) {[p='a' q=~[1 2 3]] [p='b' q=~[7 4 5 6]]} > (~(add ja l) 'a' 100) {[p='a' q=~[100 1 2 3]] [p='b' q=~[4 5 6]]} > (~(add ja l) 'c' 7) {[p='a' q=~[1 2 3]] [p='c' q=~[7]] [p='b' q=~[4 5 6]]} > (~(add ja l) 'c' `(list ,@)`[7 8 9 ~]) ! type-fail ! exit ``` ** ### `++ju` Jug operations ``` ++ ju :: jug engine |/ a=(jug) ``` Container arm for jug operation arms. A `++jug` is a `++map` of `++sets`. The contained arms inherit its sample jug, `a`. `a` is a jug. ``` > ~(. ju (mo (limo a=(sa "ho") b=(sa "he") ~))) <2.dgz [nlr([p={%a %b} q={nlr(^$1{@tD $1}) nlr(^$3{@tD $3})}]) <414.fvk 101.jzo 1.ypj %164>]> ``` ### `+-del:ju` Remove #### Source ``` +- del :: del key-set pair |* [b=* c=*] ^+ a =+ d=(get b) =+ e=(~(del in d) c) ?~ e (~(del by a) b) (~(put by a) b e) :: ``` Produces jug `a` with value `c` removed from set located at key `b`. `a` is a jug. `b` is a key of the same type as the keys in `a`. `c` is the value of the same type of the keys in `a` that is to be removed. ``` > s [[p='a' q={1 3 2}] [p='b' q={5 4 6}]} > (~(del ju s) 'a' 1) {[p='a' q={3 2}] [p='b' q={5 4 6}]} > (~(del ju s) 'c' 7) {[p='a' q={1 3 2}] [p='b' q={5 4 6}]} ``` --- ### `+-get:ju` Retrieve set ``` +- get :: gets set by key |* b=* =+ c=(~(get by a) b) ?~(c ~ u.c) :: ``` Produces a set retrieved from jar `a` using key `b`. `a` is a jar. `b` is a key of the same type as the keys in `a`. ``` > s {[p='a' q={1 3 2}] [p='b' q={5 4 6}]} > (~(get ju s) 'a') {1 3 2} > (~(get ju s) 'b') {5 4 6} > (~(get ju s) 'c') ~ ``` --- ### `+-has:ju` Check contents ``` +- has :: existence check |* [b=* c=*] ^- ? (~(has in (get b)) c) :: ``` Computes whether a value `c` exists within the set located at key `b` with jar `a`. Produces a loobean. `a` is a set. `b` is a key as a noun. `c` is a value as a noun. ``` > s {[p='a' q={1 3 2}] [p='b' q={5 4 6}]} > (~(has ju s) 'a' 3) %.y > (~(has ju s) 'b' 6) %.y > (~(has ju s) 'a' 7) %.n > (~(has jus s) 'c' 7) ! -find-limb.jus ! find-none ! exit > (~(has ju s) 'c' 7) %.n ``` --- ### `+-put:ju` Add key-set pair ``` +- put |* {b=* c=*} ^+ a =+ d=(get b) (~(put by a) b (~(put in d) c)) ``` Produces jar `a` with `c` added to the set value located at key `b`. `a` is a set. `b` is a key as a noun. `c` is a value. ``` > s [p='a' q=[1 3 2]] [p='b' q=[5 4 6]]] > (~(put ju s) 'a' 7) {[p='a' q={7 1 3 2}] [p='b' q={5 4 6}]} > (~(put ju s) 'a' 1) {[p='a' q={1 3 2}] [p='b' q={5 4 6}]} > (~(put ju s) 'c' 7) {[p='a' q={1 3 2}] [p='c' q={7}] [p='b' q={5 4 6}]} ``` ---