on master help sign in
Updated syntax for 1a
fc52722rmariani
docs/hoon/library/1a.md+472−10
@@ -27,7 +27,7 @@ Source
27
27
28 ++ add :: add
28 ++ add :: add
29 ~/ %add
29 ~/ %add
30− |= [a/@ b/@]
30+ |= [a=@ b=@]
31 ^- @
31 ^- @
32 ?: =(0 a) b
32 ?: =(0 a) b
33 $(a (dec a), b +(b))
33 $(a (dec a), b +(b))
@@ -64,7 +64,469 @@ Source
64
64
65 ++ dec :: decrement
65 ++ dec :: decrement
66 ~/ %dec
66 ~/ %dec
67− |= a/@
67+ |= a=@
68+ ~_ leaf+"decrement-underflow"
69+ ?< =(0 a)
70+ =+ b=0
71+ |- ^- @
72+ ?: =(a +(b)) b
73+ $(b +(b))
74+
75+Examples
76+--------
77+
78+ > (dec 7)
79+ 6
80+ > (dec 0)
81+ ! decrement-underflow
82+ ! exit
83+
84+
85+
86+***
87+### `++div`
88+
89+Divide
90+
91+Computes `a` divided by `b`.
92+
93+Accepts
94+-------
95+
96+`a` is an atom.
97+
98+`b` is an atom.
99+
100+Produces
101+--------
102+
103+An atom.
104+
105+Source
106+------
107+
108+ ++ div :: divide
109+ ~/ %div
110+ |: [a=`@`1 b=`@`1]
111+ :> quotient
112+ ^- @
113+ ~_ leaf+"divide-by-zero"
114+ ?< =(0 b)
115+ =+ c=0
116+ |-
117+ ?: (lth a b) c
118+ $(a (sub a b), c +(c))
119+ ::
120+
121+Examples
122+--------
123+
124+ > (div 4 2)
125+ 2
126+ > (div 17 8)
127+ 2
128+ > (div 20 30)
129+ 0
130+
131+
132+***
133+### `++gte`
134+
135+Greater-than/equal
136+
137+Tests whether `a` is greater than a number `b`.
138+
139+Accepts
140+-------
141+
142+`a` is an atom.
143+
144+`b` is an atom.
145+
146+Produces
147+--------
148+
149+A boolean.
150+
151+Source
152+------
153+
154+ ++ gte :: greater-equal
155+ ~/ %gte
156+ |= [a=@ b=@]
157+ ^- ?
158+ !(lth a b)
159+
160+
161+Examples
162+--------
163+
164+ > (gte 100 10)
165+ %.y
166+ > (gte 4 4)
167+ %.y
168+ > (gte 3 4)
169+ %.n
170+
171+
172+
173+***
174+### `++gth`
175+
176+Greater-than
177+
178+Tests whether `a` is greater than `b`.
179+
180+Accepts
181+-------
182+
183+`a` is an atom.
184+
185+`b` is an atom.
186+
187+Produces
188+--------
189+
190+A boolean.
191+
192+Source
193+------
194+
195+ ++ gth :: greater-than
196+ ~/ %gth
197+ |= [a=@ b=@]
198+ ^- ?
199+ !(lte a b)
200+
201+
202+
203+Examples
204+--------
205+
206+ > (gth 'd' 'c')
207+ %.y
208+ > (gth ~h1 ~m61)
209+ %.n
210+
211+
212+
213+***
214+### `++lte`
215+
216+Less-than/equal
217+
218+Tests whether `a` is less than or equal to `b`.
219+
220+Accepts
221+-------
222+
223+`a` is an atom.
224+
225+`b` is an atom.
226+
227+Produces
228+--------
229+
230+A boolean.
231+
232+Source
233+------
234+
235+ ++ lte :: less-equal
236+ ~/ %lte
237+ |= [a=@ b=@]
238+ |(=(a b) (lth a b))
239+
240+ ::
241+
242+Examples
243+--------
244+
245+ > (lte 4 5)
246+ %.y
247+ > (lte 5 4)
248+ %.n
249+ > (lte 5 5)
250+ %.y
251+ > (lte 0 0)
252+ %.y
253+
254+
255+
256+***
257+### `++lth`
258+
259+Less-than
260+
261+Tests whether `a` is less than `b`.
262+
263+Accepts
264+-------
265+
266+`a` is an atom.
267+
268+`b` is an atom.
269+
270+Produces
271+--------
272+
273+A boolean.
274+
275+Source
276+------
277+
278+ ++ lth :: less-than
279+ ~/ %lth
280+ |= [a=@ b=@]
281+ ^- ?
282+ ?& !=(a b)
283+ |-
284+ ?| =(0 a)
285+ ?& !=(0 b)
286+ $(a (dec a), b (dec b))
287+ == == ==
288+
289+Examples
290+--------
291+
292+ > (lth 4 5)
293+ %.y
294+ > (lth 5 4)
295+ %.n
296+ > (lth 5 5)
297+ %.n
298+ > (lth 5 0)
299+ %.n
300+
301+
302+***
303+### `++max`
304+
305+Maximum
306+
307+Computes the greater of `a` and `b`.
308+
309+Accepts
310+-------
311+
312+`a` is an atom.
313+
314+`b` is an atom.
315+
316+Produces
317+--------
318+
319+An atom.
320+
321+Source
322+------
323+
324+ ++ max :: maximum
325+ ~/ %max
326+ |= [a=@ b=@]
327+ ^- @
328+ ?: (gth a b) a
329+ b
330+
331+Examples
332+--------
333+
334+ > (max 10 100)
335+ 100
336+ > (max 10.443 9)
337+ 10.443
338+ > (max 0 1)
339+ 1
340+
341+
342+
343+***
344+### `++min`
345+
346+Minimum
347+
348+Computes the lesser of `a` and `b`.
349+
350+Accepts
351+-------
352+
353+`a` is an atom.
354+
355+`b` is an atom.
356+
357+Produces
358+--------
359+
360+An atom.
361+
362+Source
363+------
364+
365+ ++ min :: minimum
366+ ~/ %min
367+ |= [a=@ b=@]
368+ ^- @
369+ ?: (lth a b) a
370+ b
371+
372+Examples
373+--------
374+
375+ > (min 10 100)
376+ 10
377+ > (min 10.443 9)
378+ 9
379+ > (min 0 1)
380+ 0
381+
382+
383+
384+***
385+### `++mod`
386+
387+Modulus
388+
389+Computes the remainder of dividing `a` by `b`.
390+
391+Accepts
392+-------
393+
394+`a` is an atom.
395+
396+`b` is an atom.
397+
398+Produces
399+--------
400+
401+An atom.
402+
403+Source
404+------
405+
406+ ++ mod :: remainder
407+ ~/ %mod
408+ |: [a=`@`1 b=`@`1]
409+ ^- @
410+ ?< =(0 b)
411+ (sub a (mul b (div a b)))
412+
413+
414+Examples
415+--------
416+
417+ > (mod 5 2)
418+ 1
419+ > (mod 5 5)
420+ 0
421+
422+
423+
424+***
425+### `++mul`
426+
427+Multiply
428+
429+Multiplies `a` by `b`.
430+
431+Accepts
432+-------
433+
434+`a` is an atom.
435+
436+`b` is an atom.
437+
438+Produces
439+--------
440+
441+An atom.
442+
443+Source
444+------
445+
446+ ++ mul :: multiply
447+ ~/ %mul
448+ |: [a=`@`1 b=`@`1]
449+ ^- @
450+ =+ c=0
451+ |-
452+ ?: =(0 a) c
453+ $(a (dec a), c (add b c))
454+
455+Examples
456+--------
457+
458+ > (mul 3 4)
459+ 12
460+ > (mul 0 1)
461+ 0
462+
463+
464+
465+***
466+### `++sub`
467+
468+Subtract
469+
470+Subtracts `b` from `a`.
471+
472+Accepts
473+-------
474+
475+`a` is an atom.
476+
477+`b` is an atom.
478+
479+Produces
480+--------
481+
482+An atom.
483+
484+Source
485+------
486+
487+ ++ sub :: subtract
488+ ~/ %sub
489+ |= [a=@ b=@]
490+ ~| %subtract-underflow
491+ ^- @
492+ ?: =(0 b) a
493+ $(a (dec a), b (dec b))
494+
495+Examples
496+--------
497+
498+ > (sub 10 5)
499+ 5
500+ > (sub 243 44)
501+ 199
502+ > (sub 5 0)
503+ 5
504+ > (sub 0 5)
505+ ! subtract-underflow
506+ ! exit
507+
508+
509+
510+***
511+
512+Decrements `a` by `1`.
513+
514+Accepts
515+-------
516+
517+`a` is an atom.
518+
519+Produces
520+--------
521+
522+An atom.
523+
524+Source
525+------
526+
527+ ++ dec :: decrement
528+ ~/ %dec
529+ |= a=@
68 ~| %decrement-underflow
530 ~| %decrement-underflow
69 ?< =(0 a)
531 ?< =(0 a)
70 =+ b=0
532 =+ b=0
@@ -107,7 +569,7 @@ Source
107
569
108 ++ div :: divide
570 ++ div :: divide
109 ~/ %div
571 ~/ %div
110− |= [a/@ b/@]
572+ |= [a=@ b=@]
111 ^- @
573 ^- @
112 ~| 'div'
574 ~| 'div'
113 ?< =(0 b)
575 ?< =(0 b)
@@ -152,7 +614,7 @@ Source
152
614
153 ++ gte :: greater-equal
615 ++ gte :: greater-equal
154 ~/ %gte
616 ~/ %gte
155− |= {a/@ b/@}
617+ |= [a=@ b=@]
156 ^- ?
618 ^- ?
157 !(lth a b)
619 !(lth a b)
158
620
@@ -193,7 +655,7 @@ Source
193
655
194 ++ gth :: greater-than
656 ++ gth :: greater-than
195 ~/ %gth
657 ~/ %gth
196− |= {a/@ b/@}
658+ |= [a=@ b=@]
197 ^- ?
659 ^- ?
198 !(lte a b)
660 !(lte a b)
199
661
@@ -233,7 +695,7 @@ Source
233
695
234 ++ lte :: less-equal
696 ++ lte :: less-equal
235 ~/ %lte
697 ~/ %lte
236− |= {a/@ b/@}
698+ |= [a=@ b=@]
237 |(=(a b) (lth a b))
699 |(=(a b) (lth a b))
238
700
239 ::
701 ::
@@ -276,7 +738,7 @@ Source
276
738
277 ++ lth :: less-than
739 ++ lth :: less-than
278 ~/ %lth
740 ~/ %lth
279− |= {a/@ b/@}
741+ |= [a=@ b=@]
280 ^- ?
742 ^- ?
281 ?& !=(a b)
743 ?& !=(a b)
282 |-
744 |-
@@ -322,7 +784,7 @@ Source
322
784
323 ++ max :: maximum
785 ++ max :: maximum
324 ~/ %max
786 ~/ %max
325− |= {a/@ b/@}
787+ |= [a=@ b=@]
326 ^- @
788 ^- @
327 ?: (gth a b) a
789 ?: (gth a b) a
328 b
790 b
@@ -363,7 +825,7 @@ Source
363
825
364 ++ min :: minimum
826 ++ min :: minimum
365 ~/ %min
827 ~/ %min
366− |= {a/@ b/@}
828+ |= [a=@ b=@]
367 ^- @
829 ^- @
368 ?: (lth a b) a
830 ?: (lth a b) a
369 b
831 b
@@ -485,7 +947,7 @@ Source
485
947
486 ++ sub :: subtract
948 ++ sub :: subtract
487 ~/ %sub
949 ~/ %sub
488− |= [a/@ b/@]
950+ |= [a=@ b=@]
489 ~| %subtract-underflow
951 ~| %subtract-underflow
490 ^- @
952 ^- @
491 ?: =(0 b) a
953 ?: =(0 b) a