on 140ac0e help sign in
219 lines 4.9 kB history raw
1# 2j: jar and jug logic
2### `++ja`
4Jar engine
6 |_ a/(jar)
8A container arm for `++jar` operation arms. A `++jar` is a `++map` of
9`++list`s. The contained arms inherit the sample jar.
11`a` is a jar.
13 > ~(. ja (mo (limo a/"ho" b/"he" ~)))
14 <2.dgz [nlr([p={%a %b} q=""]) <414.fvk 101.jzo 1.ypj %164>]>
16------------------------------------------------------------------------
18### `+-get:ja`
20Grab value by key
22 +- get :: gets list by key
23 |* b/*
24 =+ c=(~(get by a) b)
25 ?~(c ~ u.c)
26 ::
28Produces a list retrieved from jar `a` using the key `b`.
30`a` is a `++jar`.
32`b` is a key of the same type as the keys in `a`.
34 > =l (mo `(list ,[@t (list ,@)])`[['a' `(list ,@)`[1 2 3 ~]] ['b' `(list ,@)`[4 5 6 ~]] ~])
35 > l
36 {[p='a' q=~[1 2 3]] [p='b' q=~[4 5 6]]}
37 > (~(get ja l) 'a')
38 ~[1 2 3]
39 > (~(get ja l) 'b')
40 ~[4 5 6]
41 > (~(get ja l) 'c')
42 ~
44------------------------------------------------------------------------
46### `+-add:ja`
48Prepend to list
50 +- add :: adds key-list pair
51 |* {b/* c/*}
52 =+ d=(get b)
53 (~(put by a) b [c d])
55Produces jar `a` with value `c` prepended to the list located at key
56`b`.
58`a` is a jar.
60`b` is a key of the same type as the keys in `a`.
62`c` is a value of the same type as the values in `a`.
64 > =l (mo `(list ,[@t (list ,@)])`[['a' `(list ,@)`[1 2 3 ~]] ['b' `(list ,@)`[4 5 6 ~]] ~])
65 > l
66 {[p='a' q=~[1 2 3]] [p='b' q=~[4 5 6]]}
67 > (~(add ja l) 'b' 7)
68 {[p='a' q=~[1 2 3]] [p='b' q=~[7 4 5 6]]}
69 > (~(add ja l) 'a' 100)
70 {[p='a' q=~[100 1 2 3]] [p='b' q=~[4 5 6]]}
71 > (~(add ja l) 'c' 7)
72 {[p='a' q=~[1 2 3]] [p='c' q=~[7]] [p='b' q=~[4 5 6]]}
73 > (~(add ja l) 'c' `(list ,@)`[7 8 9 ~])
74 ! type-fail
75 ! exit
77**
78### `++ju`
80Jug operations
82 ++ ju :: jug engine
83 |/ a/(jug)
85Container arm for jug operation arms. A `++jug` is a `++map` of
86`++sets`. The contained arms inherit its sample jug, `a`.
88`a` is a jug.
90 > ~(. ju (mo (limo a/(sa "ho") b/(sa "he") ~)))
91 <2.dgz [nlr([p={%a %b} q={nlr(^$1{@tD $1}) nlr(^$3{@tD $3})}]) <414.fvk 101.jzo 1.ypj %164>]>
93### `+-del:ju`
95Remove
97 +- del :: del key-set pair
98 |* {b/* c/*}
99 ^+ a
100 =+ d=(get b)
101 =+ e=(~(del in d) c)
102 ?~ e
103 (~(del by a) b)
104 (~(put by a) b e)
105 ::
108Produces jug `a` with value `c` removed from set located at key `b`.
110`a` is a jug.
112`b` is a key of the same type as the keys in `a`.
114`c` is the value of the same type of the keys in `a` that is to be
115removed.
117 > s
118 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
119 > (~(del ju s) 'a' 1)
120 {[p='a' q={3 2}] [p='b' q={5 4 6}]}
121 > (~(del ju s) 'c' 7)
122 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
124------------------------------------------------------------------------
126### `+-get:ju`
128Retrieve set
130 +- get :: gets set by key
131 |* b/*
132 =+ c=(~(get by a) b)
133 ?~(c ~ u.c)
134 ::
136Produces a set retrieved from jar `a` using key `b`.
138`a` is a jar.
140`b` is a key of the same type as the keys in `a`.
142 > s
143 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
144 > (~(get ju s) 'a')
145 {1 3 2}
146 > (~(get ju s) 'b')
147 {5 4 6}
148 > (~(get ju s) 'c')
149 ~
151------------------------------------------------------------------------
153### `+-has:ju`
155Check contents
157 +- has :: existence check
158 |* {b/* c/*}
159 ^- ?
160 (~(has in (get b)) c)
161 ::
164Computes whether a value `c` exists within the set located at key `b`
165with jar `a`. Produces a loobean.
167`a` is a set.
169`b` is a key as a noun.
171`c` is a value as a noun.
173 > s
174 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
175 > (~(has ju s) 'a' 3)
176 %.y
177 > (~(has ju s) 'b' 6)
178 %.y
179 > (~(has ju s) 'a' 7)
180 %.n
181 > (~(has jus s) 'c' 7)
182 ! -find-limb.jus
183 ! find-none
184 ! exit
185 > (~(has ju s) 'c' 7)
186 %.n
188------------------------------------------------------------------------
190### `+-put:ju`
192Add key-set pair
194 +- put :: add key-set pair
195 |* {b/* c/*}
196 ^+ a
197 =+ d=(get b)
198 (~(put by a) b (~(put in d) c))
200Produces jar `a` with `c` added to the set value located at key `b`.
202`a` is a set.
204`b` is a key as a noun.
206`c` is a value.
208 > s
209 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
210 > (~(put ju s) 'a' 7)
211 {[p='a' q={7 1 3 2}] [p='b' q={5 4 6}]}
212 > (~(put ju s) 'a' 1)
213 {[p='a' q={1 3 2}] [p='b' q={5 4 6}]}
214 > (~(put ju s) 'c' 7)
215 {[p='a' q={1 3 2}] [p='c' q={7}] [p='b' q={5 4 6}]}
219***