on c19bc7a help sign in
275 lines 4.7 kB history raw
1:- :~ navhome/'/docs/'
2 sort/'13'
3 title/'2j: Jar and Jug Logic'
4 ==
6;>
8# 2j: jar and jug logic
10### `++ja`
12Jar engine
14```
15 |_ a=(jar)
16```
18A container arm for `++jar` operation arms. A `++jar` is a `++map` of
19`++list`s. The contained arms inherit the sample jar.
21`a` is a jar.
23```
24 > ~(. ja (mo (limo a/"ho" b/"he" ~)))
25 <2.dgz [nlr([p={%a %b} q=""]) <414.fvk 101.jzo 1.ypj %164>]>
26```
28---
29### `+-get:ja`
31Grab value by key
33```
34 +- get :: gets list by key
35 |* b=*
36 =+ c=(~(get by a) b)
37 ?~(c ~ u.c)
38```
40#### Accepts
42`a` is a `++jar`.
44`b` is a key of the same type as the keys in `a`.
46#### Produces
48A list retrieved from jar `a` using the key `b`.
50Examples
52```
53 > =l (mo `(list ,[@t (list ,@)])`[['a' `(list ,@)`[1 2 3 ~]] ['b' `(list ,@)`[4 5 6 ~]] ~])
54 > l
55 [[p='a' q=~[1 2 3]] [p='b' q=~[4 5 6]]}
57 > (~(get ja l) 'a')
58 ~[1 2 3]
60 > (~(get ja l) 'b')
61 ~[4 5 6]
63 > (~(get ja l) 'c')
64 ~
65```
67---
68### `+-add:ja`
70Prepend to list
72#### Source
74```
75 +- add :: adds key-list pair
76 |* [b=* c=*]
77 =+ d=(get b)
78 (~(put by a) b [c d])
79```
81#### Accepts
83`a` is a jar.
85`b` is a key of the same type as the keys in `a`.
87`c` is a value of the same type as the values in `a`.
89#### Examples
91```
92 > =l (mo `(list ,[@t (list ,@)])`[['a' `(list ,@)`[1 2 3 ~]] ['b' `(list ,@)`[4 5 6 ~]] ~])
93 > l
94 {[p='a' q=~[1 2 3]] [p='b' q=~[4 5 6]]}
96 > (~(add ja l) 'b' 7)
97 {[p='a' q=~[1 2 3]] [p='b' q=~[7 4 5 6]]}
99 > (~(add ja l) 'a' 100)
100 {[p='a' q=~[100 1 2 3]] [p='b' q=~[4 5 6]]}
102 > (~(add ja l) 'c' 7)
103 {[p='a' q=~[1 2 3]] [p='c' q=~[7]] [p='b' q=~[4 5 6]]}
105 > (~(add ja l) 'c' `(list ,@)`[7 8 9 ~])
106 ! type-fail
107 ! exit
108```
110**
111### `++ju`
113Jug operations
115```
116 ++ ju :: jug engine
117 |/ a=(jug)
118```
120Container arm for jug operation arms. A `++jug` is a `++map` of
121`++sets`. The contained arms inherit its sample jug, `a`.
123`a` is a jug.
125```
126 > ~(. ju (mo (limo a=(sa "ho") b=(sa "he") ~)))
127 <2.dgz [nlr([p={%a %b} q={nlr(^$1{@tD $1}) nlr(^$3{@tD $3})}]) <414.fvk 101.jzo 1.ypj %164>]>
128```
130### `+-del:ju`
132Remove
135#### Source
137```
138 +- del :: del key-set pair
139 |* [b=* c=*]
140 ^+ a
141 =+ d=(get b)
142 =+ e=(~(del in d) c)
143 ?~ e
144 (~(del by a) b)
145 (~(put by a) b e)
146 ::
147```
149Produces jug `a` with value `c` removed from set located at key `b`.
151`a` is a jug.
153`b` is a key of the same type as the keys in `a`.
155`c` is the value of the same type of the keys in `a` that is to be
156removed.
158```
159 > s
160 [[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
162 > (~(del ju s) 'a' 1)
163 {[p='a' q={3 2}] [p='b' q={5 4 6}]}
165 > (~(del ju s) 'c' 7)
166 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
167```
169---
171### `+-get:ju`
173Retrieve set
175```
176 +- get :: gets set by key
177 |* b=*
178 =+ c=(~(get by a) b)
179 ?~(c ~ u.c)
180 ::
181```
183Produces a set retrieved from jar `a` using key `b`.
185`a` is a jar.
187`b` is a key of the same type as the keys in `a`.
189```
190 > s
191 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
192 > (~(get ju s) 'a')
193 {1 3 2}
194 > (~(get ju s) 'b')
195 {5 4 6}
196 > (~(get ju s) 'c')
197 ~
198```
200---
201### `+-has:ju`
203Check contents
205```
206 +- has :: existence check
207 |* [b=* c=*]
208 ^- ?
209 (~(has in (get b)) c)
210 ::
211```
213Computes whether a value `c` exists within the set located at key `b`
214with jar `a`. Produces a loobean.
216`a` is a set.
218`b` is a key as a noun.
220`c` is a value as a noun.
222```
223 > s
224 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
225 > (~(has ju s) 'a' 3)
226 %.y
227 > (~(has ju s) 'b' 6)
228 %.y
229 > (~(has ju s) 'a' 7)
230 %.n
231 > (~(has jus s) 'c' 7)
232 ! -find-limb.jus
233 ! find-none
234 ! exit
235 > (~(has ju s) 'c' 7)
236 %.n
237```
238---
240### `+-put:ju`
242Add key-set pair
244```
245 +- put
246 |* {b=* c=*}
247 ^+ a
248 =+ d=(get b)
249 (~(put by a) b (~(put in d) c))
250```
252Produces jar `a` with `c` added to the set value located at key `b`.
254`a` is a set.
256`b` is a key as a noun.
258`c` is a value.
260```
261 > s
262 [p='a' q=[1 3 2]] [p='b' q=[5 4 6]]]
264 > (~(put ju s) 'a' 7)
265 {[p='a' q={7 1 3 2}] [p='b' q={5 4 6}]}
267 > (~(put ju s) 'a' 1)
268 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
270 > (~(put ju s) 'c' 7)
271 {[p='a' q={1 3 2}] [p='c' q={7}] [p='b' q={5 4 6}]}
272```
275---