on 6d45ede help sign in
203 lines 2.8 kB history raw
1---
2navhome: /docs
3---
6# 2n: functional hacks
7### `++cork`
9Build `f` such that `(f x) .= (b (a x))`.
11`a` is a noun.
13`b` is a gate.
15Source
16------
18 ++ cork |*({a/_|=(* **) b/gate} (corl b a)) :: compose forward
21Examples
22--------
24 > (:(cork dec dec dec) 20)
25 17
26 > =mal (mo (limo a+15 b+23 ~))
27 > ((cork ~(got by mal) dec) %a)
28 14
29 > ((cork ~(got by mal) dec) %b)
30 22
34***
35### `++corl`
37Gate compose
39XX Revisit
41`a` is a gate.
43`b` is a noun.
45Source
46------
48 ++ corl :: compose backwards
49 |* {a/gate b/_|=(* **)}
50 =< +:|.((a (b))) :: span check
51 |* c/_+<.b
52 (a (b c))
53 ::
55Examples
56--------
58 > ((corl (lift bex) (slat %ud)) '2')
59 [~ 4]
63***
64### `++curr`
66Right curry
68Right curry a gate, binding the tail of its sample
70Accepts
71-------
73`a` is a gate.
75`c` is a noun.
77Produces
78--------
81Source
82------
84 ++ curr :: curry right
85 |* {a/_|=(^ **) c/*}
86 |* b/_+<+.a
87 (a b c)
88 ::
90Examples
91--------
93 > =tep (curr scan sym)
94 > `@t`(tep "asd")
95 'asd'
96 > `@t`(tep "lek-om")
97 'lek-om'
101***
102### `++cury`
104Curry a gate, binding the head of its sample
106Accepts
107-------
109`a` is a gate.
111`b` is a noun.
113Produces
114--------
116A gate.
118Source
119------
121 ++ cury :: curry left
122 |* {a/_|=(^ **) b/*}
123 |* c/_+<+.a
124 (a b c)
125 ::
128Examples
129--------
131 > =mol (cury add 2)
132 > (mol 4)
133 6
134 > (mol 7)
135 9
139***
140### `++hard`
142Demands that a specific type be produced, crashing the program is it is
143not.
145Source
146------
148 ++ hard :: force coerce to span
149 |* han/mold
150 |= fud/* ^- han
151 ~| %hard
152 =+ gol=(han fud)
153 ?>(=(gol fud) gol)
154 ::
156Examples
157--------
159 > ((hard (list)) (limo [1 2 3 ~]))
160 ~[1 2 3]
161 > ((hard @) (add 2 2))
162 4
163 > ((hard @t) (crip "Tape to cord, bro!"))
164 'Tape to cord, bro'
165 > ((hard tape) (crip "...Tape to cord, bro?..."))
166 ! hard
167 ! exit
171***
172### `++soft`
174Politely requests a specific type to be produced, producing null if it
175is not.
177Source
178------
180 ++ soft :: maybe coerce to span
181 |* han/$-(* *)
182 |= fud/* ^- (unit han)
183 =+ gol=(han fud)
184 ?.(=(gol fud) ~ [~ gol])
185 ::
187Examples
188--------
190 > ((soft %4) (add 2 2))
191 [~ %4]
192 > ((soft @) (add 2 2))
193 [~ 4]
194 > ((soft %5) (add 2 2))
195 ~
196 > ((soft @t) (crip "Tape to cord, Woohoo!"))
197 [~ 'Tape to cord, Woohoo!']
198 > ((soft @t) (trip 'Cmon man... Tape to cord? Please?!'))
199 ~
203***