on b93c19b help sign in
271 lines 4.7 kB history raw
1+++
2title = "2j: Jar and Jug Logic"
3weight = 13
4template = "doc.html"
5+++
6### `++ja`
8Jar engine
10```
11 |_ a=(jar)
12```
14A container arm for `++jar` operation arms. A `++jar` is a `++map` of
15`++list`s. The contained arms inherit the sample jar.
17`a` is a jar.
19```
20 > ~(. ja (mo (limo a/"ho" b/"he" ~)))
21 <2.dgz [nlr([p={%a %b} q=""]) <414.fvk 101.jzo 1.ypj %164>]>
22```
24---
25### `+-get:ja`
27Grab value by key
29```
30 +- get :: gets list by key
31 |* b=*
32 =+ c=(~(get by a) b)
33 ?~(c ~ u.c)
34```
36#### Accepts
38`a` is a `++jar`.
40`b` is a key of the same type as the keys in `a`.
42#### Produces
44A list retrieved from jar `a` using the key `b`.
46Examples
48```
49 > =l (mo `(list ,[@t (list ,@)])`[['a' `(list ,@)`[1 2 3 ~]] ['b' `(list ,@)`[4 5 6 ~]] ~])
50 > l
51 [[p='a' q=~[1 2 3]] [p='b' q=~[4 5 6]]}
53 > (~(get ja l) 'a')
54 ~[1 2 3]
56 > (~(get ja l) 'b')
57 ~[4 5 6]
59 > (~(get ja l) 'c')
60 ~
61```
63---
64### `+-add:ja`
66Prepend to list
68#### Source
70```
71 +- add :: adds key-list pair
72 |* [b=* c=*]
73 =+ d=(get b)
74 (~(put by a) b [c d])
75```
77#### Accepts
79`a` is a jar.
81`b` is a key of the same type as the keys in `a`.
83`c` is a value of the same type as the values in `a`.
85#### Examples
87```
88 > =l (mo `(list ,[@t (list ,@)])`[['a' `(list ,@)`[1 2 3 ~]] ['b' `(list ,@)`[4 5 6 ~]] ~])
89 > l
90 {[p='a' q=~[1 2 3]] [p='b' q=~[4 5 6]]}
92 > (~(add ja l) 'b' 7)
93 {[p='a' q=~[1 2 3]] [p='b' q=~[7 4 5 6]]}
95 > (~(add ja l) 'a' 100)
96 {[p='a' q=~[100 1 2 3]] [p='b' q=~[4 5 6]]}
98 > (~(add ja l) 'c' 7)
99 {[p='a' q=~[1 2 3]] [p='c' q=~[7]] [p='b' q=~[4 5 6]]}
101 > (~(add ja l) 'c' `(list ,@)`[7 8 9 ~])
102 ! type-fail
103 ! exit
104```
106**
107### `++ju`
109Jug operations
111```
112 ++ ju :: jug engine
113 |/ a=(jug)
114```
116Container arm for jug operation arms. A `++jug` is a `++map` of
117`++sets`. The contained arms inherit its sample jug, `a`.
119`a` is a jug.
121```
122 > ~(. ju (mo (limo a=(sa "ho") b=(sa "he") ~)))
123 <2.dgz [nlr([p={%a %b} q={nlr(^$1{@tD $1}) nlr(^$3{@tD $3})}]) <414.fvk 101.jzo 1.ypj %164>]>
124```
126### `+-del:ju`
128Remove
131#### Source
133```
134 +- del :: del key-set pair
135 |* [b=* c=*]
136 ^+ a
137 =+ d=(get b)
138 =+ e=(~(del in d) c)
139 ?~ e
140 (~(del by a) b)
141 (~(put by a) b e)
142 ::
143```
145Produces jug `a` with value `c` removed from set located at key `b`.
147`a` is a jug.
149`b` is a key of the same type as the keys in `a`.
151`c` is the value of the same type of the keys in `a` that is to be
152removed.
154```
155 > s
156 [[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
158 > (~(del ju s) 'a' 1)
159 {[p='a' q={3 2}] [p='b' q={5 4 6}]}
161 > (~(del ju s) 'c' 7)
162 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
163```
165---
167### `+-get:ju`
169Retrieve set
171```
172 +- get :: gets set by key
173 |* b=*
174 =+ c=(~(get by a) b)
175 ?~(c ~ u.c)
176 ::
177```
179Produces a set retrieved from jar `a` using key `b`.
181`a` is a jar.
183`b` is a key of the same type as the keys in `a`.
185```
186 > s
187 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
188 > (~(get ju s) 'a')
189 {1 3 2}
190 > (~(get ju s) 'b')
191 {5 4 6}
192 > (~(get ju s) 'c')
193 ~
194```
196---
197### `+-has:ju`
199Check contents
201```
202 +- has :: existence check
203 |* [b=* c=*]
204 ^- ?
205 (~(has in (get b)) c)
206 ::
207```
209Computes whether a value `c` exists within the set located at key `b`
210with jar `a`. Produces a loobean.
212`a` is a set.
214`b` is a key as a noun.
216`c` is a value as a noun.
218```
219 > s
220 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
221 > (~(has ju s) 'a' 3)
222 %.y
223 > (~(has ju s) 'b' 6)
224 %.y
225 > (~(has ju s) 'a' 7)
226 %.n
227 > (~(has jus s) 'c' 7)
228 ! -find-limb.jus
229 ! find-none
230 ! exit
231 > (~(has ju s) 'c' 7)
232 %.n
233```
234---
236### `+-put:ju`
238Add key-set pair
240```
241 +- put
242 |* {b=* c=*}
243 ^+ a
244 =+ d=(get b)
245 (~(put by a) b (~(put in d) c))
246```
248Produces jar `a` with `c` added to the set value located at key `b`.
250`a` is a set.
252`b` is a key as a noun.
254`c` is a value.
256```
257 > s
258 [p='a' q=[1 3 2]] [p='b' q=[5 4 6]]]
260 > (~(put ju s) 'a' 7)
261 {[p='a' q={7 1 3 2}] [p='b' q={5 4 6}]}
263 > (~(put ju s) 'a' 1)
264 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
266 > (~(put ju s) 'c' 7)
267 {[p='a' q={1 3 2}] [p='c' q={7}] [p='b' q={5 4 6}]}
268```
271---