on 8564483 help sign in
201 lines 2.7 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 ++ cury :: curry left
149 |* {a/_|=(^ **) b/*}
150 |* c/_+<+.a
151 (a b c)
152 ::
154Examples
155--------
157 > ((hard (list)) (limo [1 2 3 ~]))
158 ~[1 2 3]
159 > ((hard @) (add 2 2))
160 4
161 > ((hard @t) (crip "Tape to cord, bro!"))
162 'Tape to cord, bro'
163 > ((hard tape) (crip "...Tape to cord, bro?..."))
164 ! hard
165 ! exit
169***
170### `++soft`
172Politely requests a specific type to be produced, producing null if it
173is not.
175Source
176------
178 ++ soft :: maybe coerce to span
179 |* han/$-(* *)
180 |= fud/* ^- (unit han)
181 =+ gol=(han fud)
182 ?.(=(gol fud) ~ [~ gol])
183 ::
185Examples
186--------
188 > ((soft %4) (add 2 2))
189 [~ %4]
190 > ((soft @) (add 2 2))
191 [~ 4]
192 > ((soft %5) (add 2 2))
193 ~
194 > ((soft @t) (crip "Tape to cord, Woohoo!"))
195 [~ 'Tape to cord, Woohoo!']
196 > ((soft @t) (trip 'Cmon man... Tape to cord? Please?!'))
197 ~
201***