@@ -4,157 +4,151 @@ navhome: /docs/
44
55
66# 2n: functional hacks
7+
78### `++cork`
89
10+Compose forward
11+
912Build `f` such that `(f x) .= (b (a x))`.
1013
14+#### Accepts
15+
1116`a` is a noun.
1217
1318`b` is a gate.
1419
15−Source
16−------
17−
18− ++ cork |*({a/_|=(* **) b/gate} (corl b a)) :: compose forward
20+#### Source
1921
22+ ++ cork |*([a=_|=(* **) b=gate] (corl b a))
2023
21−Examples
22−--------
24+#### Examples
2325
2426 > (:(cork dec dec dec) 20)
2527 17
28+
2629 > =mal (mo (limo a+15 b+23 ~))
2730 > ((cork ~(got by mal) dec) %a)
2831 14
32+
2933 > ((cork ~(got by mal) dec) %b)
3034 22
3135
3236
33−
3437***
3538### `++corl`
3639
37−Gate compose
40+Compose backward
3841
39−XX Revisit
42+Build `f` such that
43+
44+#### Accepts
4045
4146`a` is a gate.
4247
4348`b` is a noun.
4449
45−Source
46−------
50+#### Source
4751
48− ++ corl :: compose backwards
49− |* {a/gate b/_|=(* **)}
52+ ++ corl
53+ |* [a=gate b=_|=(* **)]
5054 =< +:|.((a (b))) :: span check
51− |* c/_+<.b
55+ |* c=_+<.b
5256 (a (b c))
5357 ::
5458
55−Examples
56−--------
59+#### Examples
5760
5861 > ((corl (lift bex) (slat %ud)) '2')
5962 [~ 4]
6063
6164
62−
6365***
6466### `++curr`
6567
6668Right curry
6769
68−Right curry a gate, binding the tail of its sample
70+Right-curry a gate, binding the tail of its sample
6971
70−Accepts
71−-------
72+#### Accepts
7273
7374`a` is a gate.
7475
7576`c` is a noun.
7677
77−Produces
78−--------
78+#### Produces
7979
80+A gate.
8081
81−Source
82−------
82+#### Source
8383
84− ++ curr :: curry right
85− |* {a/_|=(^ **) c/*}
86− |* b/_+<+.a
84+ ++ curr
85+ |* [a=_|=(^ **) c=*}
86+ |* b=_+<+.a
8787 (a b c)
88− ::
8988
90−Examples
91−--------
89+#### Examples
9290
93− > =tep (curr scan sym)
91+ > =tep (cury scan sym)
9492 > `@t`(tep "asd")
9593 'asd'
94+
9695 > `@t`(tep "lek-om")
9796 'lek-om'
9897
9998
100−
10199***
102100### `++cury`
103101
102+Curry left
103+
104104Curry a gate, binding the head of its sample
105105
106−Accepts
107−-------
106+#### Accepts
108107
109108`a` is a gate.
110109
111110`b` is a noun.
112111
113−Produces
114−--------
112+#### Produces
115113
116114A gate.
117115
118−Source
119−------
116+#### Source
120117
121− ++ cury :: curry left
122− |* {a/_|=(^ **) b/*}
123− |* c/_+<+.a
118+ ++ cury
119+ |* [a=_|=(^ **) b=*}
120+ |* c=_+<+.a
124121 (a b c)
125− ::
126122
127123
128−Examples
129−--------
124+#### Examples
130125
131126 > =mol (cury add 2)
132127 > (mol 4)
133128 6
129+
134130 > (mol 7)
135131 9
136132
137−
138−
139133***
140134### `++hard`
141135
136+Force remold
137+
142138Demands that a specific type be produced, crashing the program if it is
143139not.
144140
145−Source
146−------
141+#### Source
147142
148− ++ hard :: force remold
149− |* han/gate
150− |= fud/* ^- han
143+ ++ hard
144+ |* han=gate
145+ |= fud=* ^- han
151146 ~_ leaf+"hard"
152147 =+ gol=(han fud)
153148 ?>(=(gol fud) gol)
154149 ::
155150
156−Examples
157−--------
151+#### Examples
158152
159153 > ((hard (list)) (limo [1 2 3 ~]))
160154 ~[1 2 3]
@@ -171,21 +165,21 @@ Examples
171165***
172166### `++soft`
173167
168+Maybe remold
169+
174170Politely requests a specific type to be produced, producing null if it
175171is not.
176172
177−Source
178−------
173+#### Source
179174
180− ++ soft :: maybe remold
181− |* han/gate
182− |= fud/* ^- (unit han)
175+ ++ soft
176+ |* han=gate
177+ |= fud=* ^- (unit han)
183178 =+ gol=(han fud)
184179 ?.(=(gol fud) ~ [~ gol])
185180 ::
186181
187−Examples
188−--------
182+#### Examples
189183
190184 > ((soft %4) (add 2 2))
191185 [~ %4]
@@ -200,4 +194,194 @@ Examples
200194
201195
202196
197+***
198+### `++head`
199+
200+Get head
201+
202+Produces the head of a cell.
203+
204+#### Accepts
205+
206+A cell.
207+
208+#### Produces
209+
210+An atom.
211+
212+#### Source
213+
214+ ++ head |*(^ ,:+<-)
215+
216+#### Examples
217+
218+ > (head [1 2])
219+ 1
220+
221+ > (head [[1 1] 2])
222+ [1 1]
223+
224+ > (head "hello")
225+ 'h'
226+
227+
228+***
229+### `++same`
230+
231+Identity
232+
233+Produces the same value that it was given.
234+
235+#### Accepts
236+
237+A noun.
238+
239+#### Produces
240+
241+A noun.
242+
243+#### Source
244+
245+ ++ same |*(* +<)
246+
247+#### Examples
248+
249+ > (same [1 2])
250+ [1 2]
251+
252+ > (same [[1 1] 2])
253+ [[1 1] 2]
254+
255+ > (same "hello")
256+ "hello"
257+
258+***
259+### `++slog`
260+
261+Deify printf
262+
263+Produces a stack trace if the stack trace isn't null, then produces the other
264+input.
265+
266+#### Accepts
267+
268+A `tang`.
269+
270+#### Produces
271+
272+A `tang`.
273+
274+#### Source
275+
276+ ++ slog
277+ =| pri=@
278+ |= a=tang ^+ same
279+ ?~(a same ~>(%slog.[pri i.a] $(a t.a)))
280+
281+#### Examples
282+
283+ > =+ result=((slog [%leaf "error-message"]~) [12 13]) [%product result]
284+ [%product 12 13]
285+
286+#### Discussion
287+
288+`slog` is intended to be put in the middle of a bunch of chained function
289+calls that string a piece of data through them, so that an error message will be
290+printed if there's one to print.
291+
292+***
293+### `++mean`
294+
295+Crash and printf
296+
297+Ends the program and produces a `tang` tracing error message.
298+
299+#### Accepts
300+
301+`a` is a tang.
302+
303+#### Produces
304+
305+A crash.
306+
307+#### Source
308+
309+ ++ mean
310+ |= a=tang
311+ ^+ !!
312+ ?~ a !!
313+ ~_(i.a $(a t.a))
314+
315+#### Examples
316+
317+ > ~>(%mean.[%leaf "fuse-loop"] !!)
318+ ####
319+ !! crash
320+
321+***
322+### `++tail`
323+
324+Get tail
325+
326+Produces the tail of a cell.
327+
328+#### Accepts
329+
330+A cell.
331+
332+#### Produces
333+
334+A noun.
335+
336+#### Source
337+
338+ ++ tail |*(^ ,:+<+)
339+
340+#### Examples
341+
342+ > (tail [1 2])
343+ 2
344+
345+ > (tail [[1 1] 2])
346+ 2
347+
348+ > (tail "hello")
349+ "ello"
350+
351+
352+***
353+### `++test`
354+
355+Test for equality
356+
357+Checks if `a` and `b` are equal, producing a flag.
358+
359+#### Accepts
360+
361+`a` is a noun.
362+
363+`b` is a noun.
364+
365+#### Produces
366+
367+A flag.
368+
369+#### Source
370+
371+ ++ test |=(^ =(+<- +<+))
372+
373+#### Examples
374+
375+ > (test 1 1)
376+ %.y
377+
378+ > (test [2 0] 2)
379+ %.n
380+
381+ > (test "hello" 'hello')
382+ %.n
383+
384+ > (test "hello" ['h' 'e' 'l' 'l' 'o' ~])
385+ %.y
386+
203387***