on 6d45ede help sign in
224 lines 4.9 kB history raw
1---
2navhome: /docs
3---
6# 2j: jar and jug logic
7### `++ja`
9Jar engine
11 |_ a/(jar)
13A container arm for `++jar` operation arms. A `++jar` is a `++map` of
14`++list`s. The contained arms inherit the sample jar.
16`a` is a jar.
18 > ~(. ja (mo (limo a/"ho" b/"he" ~)))
19 <2.dgz [nlr([p={%a %b} q=""]) <414.fvk 101.jzo 1.ypj %164>]>
21------------------------------------------------------------------------
23### `+-get:ja`
25Grab value by key
27 +- get :: gets list by key
28 |* b/*
29 =+ c=(~(get by a) b)
30 ?~(c ~ u.c)
31 ::
33Produces a list retrieved from jar `a` using the key `b`.
35`a` is a `++jar`.
37`b` is a key of the same type as the keys in `a`.
39 > =l (mo `(list ,[@t (list ,@)])`[['a' `(list ,@)`[1 2 3 ~]] ['b' `(list ,@)`[4 5 6 ~]] ~])
40 > l
41 {[p='a' q=~[1 2 3]] [p='b' q=~[4 5 6]]}
42 > (~(get ja l) 'a')
43 ~[1 2 3]
44 > (~(get ja l) 'b')
45 ~[4 5 6]
46 > (~(get ja l) 'c')
47 ~
49------------------------------------------------------------------------
51### `+-add:ja`
53Prepend to list
55 +- add :: adds key-list pair
56 |* {b/* c/*}
57 =+ d=(get b)
58 (~(put by a) b [c d])
60Produces jar `a` with value `c` prepended to the list located at key
61`b`.
63`a` is a jar.
65`b` is a key of the same type as the keys in `a`.
67`c` is a value of the same type as the values in `a`.
69 > =l (mo `(list ,[@t (list ,@)])`[['a' `(list ,@)`[1 2 3 ~]] ['b' `(list ,@)`[4 5 6 ~]] ~])
70 > l
71 {[p='a' q=~[1 2 3]] [p='b' q=~[4 5 6]]}
72 > (~(add ja l) 'b' 7)
73 {[p='a' q=~[1 2 3]] [p='b' q=~[7 4 5 6]]}
74 > (~(add ja l) 'a' 100)
75 {[p='a' q=~[100 1 2 3]] [p='b' q=~[4 5 6]]}
76 > (~(add ja l) 'c' 7)
77 {[p='a' q=~[1 2 3]] [p='c' q=~[7]] [p='b' q=~[4 5 6]]}
78 > (~(add ja l) 'c' `(list ,@)`[7 8 9 ~])
79 ! type-fail
80 ! exit
82**
83### `++ju`
85Jug operations
87 ++ ju :: jug engine
88 |/ a/(jug)
90Container arm for jug operation arms. A `++jug` is a `++map` of
91`++sets`. The contained arms inherit its sample jug, `a`.
93`a` is a jug.
95 > ~(. ju (mo (limo a/(sa "ho") b/(sa "he") ~)))
96 <2.dgz [nlr([p={%a %b} q={nlr(^$1{@tD $1}) nlr(^$3{@tD $3})}]) <414.fvk 101.jzo 1.ypj %164>]>
98### `+-del:ju`
100Remove
102 +- del :: del key-set pair
103 |* {b/* c/*}
104 ^+ a
105 =+ d=(get b)
106 =+ e=(~(del in d) c)
107 ?~ e
108 (~(del by a) b)
109 (~(put by a) b e)
110 ::
113Produces jug `a` with value `c` removed from set located at key `b`.
115`a` is a jug.
117`b` is a key of the same type as the keys in `a`.
119`c` is the value of the same type of the keys in `a` that is to be
120removed.
122 > s
123 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
124 > (~(del ju s) 'a' 1)
125 {[p='a' q={3 2}] [p='b' q={5 4 6}]}
126 > (~(del ju s) 'c' 7)
127 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
129------------------------------------------------------------------------
131### `+-get:ju`
133Retrieve set
135 +- get :: gets set by key
136 |* b/*
137 =+ c=(~(get by a) b)
138 ?~(c ~ u.c)
139 ::
141Produces a set retrieved from jar `a` using key `b`.
143`a` is a jar.
145`b` is a key of the same type as the keys in `a`.
147 > s
148 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
149 > (~(get ju s) 'a')
150 {1 3 2}
151 > (~(get ju s) 'b')
152 {5 4 6}
153 > (~(get ju s) 'c')
154 ~
156------------------------------------------------------------------------
158### `+-has:ju`
160Check contents
162 +- has :: existence check
163 |* {b/* c/*}
164 ^- ?
165 (~(has in (get b)) c)
166 ::
169Computes whether a value `c` exists within the set located at key `b`
170with jar `a`. Produces a loobean.
172`a` is a set.
174`b` is a key as a noun.
176`c` is a value as a noun.
178 > s
179 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
180 > (~(has ju s) 'a' 3)
181 %.y
182 > (~(has ju s) 'b' 6)
183 %.y
184 > (~(has ju s) 'a' 7)
185 %.n
186 > (~(has jus s) 'c' 7)
187 ! -find-limb.jus
188 ! find-none
189 ! exit
190 > (~(has ju s) 'c' 7)
191 %.n
193------------------------------------------------------------------------
195### `+-put:ju`
197Add key-set pair
199 +- put :: add key-set pair
200 |* {b/* c/*}
201 ^+ a
202 =+ d=(get b)
203 (~(put by a) b (~(put in d) c))
205Produces jar `a` with `c` added to the set value located at key `b`.
207`a` is a set.
209`b` is a key as a noun.
211`c` is a value.
213 > s
214 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
215 > (~(put ju s) 'a' 7)
216 {[p='a' q={7 1 3 2}] [p='b' q={5 4 6}]}
217 > (~(put ju s) 'a' 1)
218 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
219 > (~(put ju s) 'c' 7)
220 {[p='a' q={1 3 2}] [p='c' q={7}] [p='b' q={5 4 6}]}
224***