on 657b415 help sign in
196 lines 2.7 kB history raw
1# 2n: functional hacks
2### `++cork`
4Build `f` such that `(f x) .= (b (a x))`.
6`a` is a noun.
8`b` is a gate.
10Source
11------
13 ++ cork |*({a/_|=(* **) b/gate} (corl b a)) :: compose forward
16Examples
17--------
19 > (:(cork dec dec dec) 20)
20 17
21 > =mal (mo (limo a+15 b+23 ~))
22 > ((cork ~(got by mal) dec) %a)
23 14
24 > ((cork ~(got by mal) dec) %b)
25 22
29***
30### `++corl`
32Gate compose
34XX Revisit
36`a` is a gate.
38`b` is a noun.
40Source
41------
43 ++ corl :: compose backwards
44 |* {a/gate b/_|=(* **)}
45 =< +:|.((a (b))) :: span check
46 |* c/_+<.b
47 (a (b c))
48 ::
50Examples
51--------
53 > ((corl (lift bex) (slat %ud)) '2')
54 [~ 4]
58***
59### `++curr`
61Right curry
63Right curry a gate, binding the tail of its sample
65Accepts
66-------
68`a` is a gate.
70`c` is a noun.
72Produces
73--------
76Source
77------
79 ++ curr :: curry right
80 |* {a/_|=(^ **) c/*}
81 |* b/_+<+.a
82 (a b c)
83 ::
85Examples
86--------
88 > =tep (curr scan sym)
89 > `@t`(tep "asd")
90 'asd'
91 > `@t`(tep "lek-om")
92 'lek-om'
96***
97### `++cury`
99Curry a gate, binding the head of its sample
101Accepts
102-------
104`a` is a gate.
106`b` is a noun.
108Produces
109--------
111A gate.
113Source
114------
116 ++ cury :: curry left
117 |* {a/_|=(^ **) b/*}
118 |* c/_+<+.a
119 (a b c)
120 ::
123Examples
124--------
126 > =mol (cury add 2)
127 > (mol 4)
128 6
129 > (mol 7)
130 9
134***
135### `++hard`
137Demands that a specific type be produced, crashing the program is it is
138not.
140Source
141------
143 ++ cury :: curry left
144 |* {a/_|=(^ **) b/*}
145 |* c/_+<+.a
146 (a b c)
147 ::
149Examples
150--------
152 > ((hard (list)) (limo [1 2 3 ~]))
153 ~[1 2 3]
154 > ((hard @) (add 2 2))
155 4
156 > ((hard @t) (crip "Tape to cord, bro!"))
157 'Tape to cord, bro'
158 > ((hard tape) (crip "...Tape to cord, bro?..."))
159 ! hard
160 ! exit
164***
165### `++soft`
167Politely requests a specific type to be produced, producing null if it
168is not.
170Source
171------
173 ++ soft :: maybe coerce to span
174 |* han/$-(* *)
175 |= fud/* ^- (unit han)
176 =+ gol=(han fud)
177 ?.(=(gol fud) ~ [~ gol])
178 ::
180Examples
181--------
183 > ((soft %4) (add 2 2))
184 [~ %4]
185 > ((soft @) (add 2 2))
186 [~ 4]
187 > ((soft %5) (add 2 2))
188 ~
189 > ((soft @t) (crip "Tape to cord, Woohoo!"))
190 [~ 'Tape to cord, Woohoo!']
191 > ((soft @t) (trip 'Cmon man... Tape to cord? Please?!'))
192 ~
196***