on master help sign in
Merge pull request #264 from urbit/rmariani-patch-4
8d7cd25Joshua Reagan
docs/hoon/library/1a.md+276−136
@@ -10,38 +10,48 @@ Add
10
10
11Produces the sum of `a` and `b`.
11Produces the sum of `a` and `b`.
12
12
13−Accepts
13+#### Accepts
14−-------
15
14
16`a` is an atom.
15`a` is an atom.
17
16
18`b` is an atom.
17`b` is an atom.
19
18
20−Produces
19+#### Produces
21−--------
22
20
23An atom.
21An atom.
24
22
25−Source
23+#### Source
26−------
27
24
28− ++ add :: add
25+ ++ add
29 ~/ %add
26 ~/ %add
30− |= [a/@ b/@]
27+ |= [a=@ b=@]
31 ^- @
28 ^- @
32 ?: =(0 a) b
29 ?: =(0 a) b
33 $(a (dec a), b +(b))
30 $(a (dec a), b +(b))
34
31
35−Examples
32+#### Examples
36−--------
37
33
38 > (add 2 2)
34 > (add 2 2)
39 4
35 4
36+
40 > (add 1 1.000.000)
37 > (add 1 1.000.000)
41 1.000.001
38 1.000.001
39+
42 > (add 1.333 (mul 2 2))
40 > (add 1.333 (mul 2 2))
43 1.337
41 1.337
44
42
43+ > (add 'a' 4)
44+ 101
45+
46+ > (add 'a' 'b')
47+ 195
48+
49+ > (add 0xc 0xf)
50+ 27
51+
52+ > `@ux`(add 0xc 0xf)
53+ 0x1b
54+
45***
55***
46### `++dec`
56### `++dec`
47
57
@@ -49,22 +59,19 @@ Decrement
49
59
50Decrements `a` by `1`.
60Decrements `a` by `1`.
51
61
52−Accepts
62+#### Accepts
53−-------
54
63
55`a` is an atom.
64`a` is an atom.
56
65
57−Produces
66+#### Produces
58−--------
59
67
60An atom.
68An atom.
61
69
62−Source
70+#### Source
63−------
64
71
65− ++ dec :: decrement
72+ ++ dec
66 ~/ %dec
73 ~/ %dec
67− |= a/@
74+ |= a=@
68 ~| %decrement-underflow
75 ~| %decrement-underflow
69 ?< =(0 a)
76 ?< =(0 a)
70 =+ b=0
77 =+ b=0
@@ -72,15 +79,25 @@ Source
72 ?: =(a +(b)) b
79 ?: =(a +(b)) b
73 $(b +(b))
80 $(b +(b))
74
81
75−Examples
82+#### Examples
76−--------
77
83
78 > (dec 7)
84 > (dec 7)
79 6
85 6
86+
80 > (dec 0)
87 > (dec 0)
81 ! decrement-underflow
88 ! decrement-underflow
82 ! exit
89 ! exit
83
90
91+ > (dec 'b')
92+ 97
93+ > `@t`(dec 'b')
94+ 'a'
95+
96+ > (dec 0xc)
97+ 11
98+ > `@ux`(dec 0xc)
99+ 0xb
100+
84
101
85
102
86***
103***
@@ -88,82 +105,135 @@ Examples
88
105
89Divide
106Divide
90
107
91−Computes `a` divided by `b`.
108+Computes `a` divided by `b` without remainder.
92
109
93−Accepts
110+#### Accepts
94−-------
95
111
96`a` is an atom.
112`a` is an atom.
97
113
98`b` is an atom.
114`b` is an atom.
99
115
100−Produces
116+#### Produces
101−--------
102
117
103An atom.
118An atom.
104
119
105−Source
120+#### Source
106−------
107
121
108− ++ div :: divide
122+ ++ div
109 ~/ %div
123 ~/ %div
110− |= [a/@ b/@]
124+ |: [a=`@`1 b=`@`1]
111 ^- @
125 ^- @
112− ~| 'div'
126+ ~_ leaf+"divide-by-zero"
113 ?< =(0 b)
127 ?< =(0 b)
114 =+ c=0
128 =+ c=0
115 |-
129 |-
116 ?: (lth a b) c
130 ?: (lth a b) c
117 $(a (sub a b), c +(c))
131 $(a (sub a b), c +(c))
118− ::
119
132
133+
120−Examples
134+#### Examples
121−--------
135+
122
136
123 > (div 4 2)
137 > (div 4 2)
124 2
138 2
139+
125 > (div 17 8)
140 > (div 17 8)
126 2
141 2
142+
127 > (div 20 30)
143 > (div 20 30)
128 0
144 0
129
145
146+ > (div 'ab' 'a')
147+ 259
148+ > `@`'ab'
149+ 25.185
150+ > `@`a
151+ 97
152+
153+ > (div 0x9f 0x29)
154+ 6
155+
156+
157+***
158+### `++dvr`
159+
160+Divide with remainder
161+
162+Computes `a` divided by `b`, producing the quotient and the remainder.
163+
164+#### Accepts
165+
166+`a` is an atom.
167+
168+`b` is an atom.
169+
170+#### Produces
171+
172+A cell of atoms.
173+
174+#### Source
175+
176+ ++ dvr
177+ ~/ %dvr
178+ |= [a=@ b=@]
179+ ^- [p=@ q=@]
180+ [(div a b) (mod a b)]
181+
182+#### Examples
183+
184+ > (dvr 17 8)
185+ [p=2 q=1]
186+
187+ > (dvr 17 6)
188+ [p=2 q=5]
189+
190+ > (dvr 18 6)
191+ [p=3 q=0]
192+
193+ > (dvr 4 2)
194+ [p=2 q=0]
195+
196+ > (dvr 'ab 'a')
197+ [p=259 q=62]
198+ > `@`'a'
199+ 97
200+ > `@`'ab'
201+ 25.185
130
202
131***
203***
132### `++gte`
204### `++gte`
133
205
134Greater-than/equal
206Greater-than/equal
135
207
136−Tests whether `a` is greater than a number `b`.
208+Tests whether `a` is greater than or equal to `b`.
137
209
138−Accepts
210+#### Accepts
139−-------
140
211
141`a` is an atom.
212`a` is an atom.
142
213
143`b` is an atom.
214`b` is an atom.
144
215
145−Produces
216+#### Produces
146−--------
147
217
148−A boolean.
218+A flag.
149
219
150−Source
220+#### Source
151−------
152
221
153− ++ gte :: greater-equal
222+ ++ gte
154 ~/ %gte
223 ~/ %gte
155− |= {a/@ b/@}
224+ |= [a=@ b=@]
156 ^- ?
225 ^- ?
157 !(lth a b)
226 !(lth a b)
158
227
159
228
160−Examples
229+#### Examples
161−--------
162
230
163 > (gte 100 10)
231 > (gte 100 10)
164 %.y
232 %.y
233+
165 > (gte 4 4)
234 > (gte 4 4)
166 %.y
235 %.y
236+
167 > (gte 3 4)
237 > (gte 3 4)
168 %.n
238 %.n
169
239
@@ -176,37 +246,36 @@ Greater-than
176
246
177Tests whether `a` is greater than `b`.
247Tests whether `a` is greater than `b`.
178
248
179−Accepts
249+#### Accepts
180−-------
181
250
182`a` is an atom.
251`a` is an atom.
183
252
184`b` is an atom.
253`b` is an atom.
185
254
186−Produces
255+#### Produces
187−--------
188
256
189−A boolean.
257+A flag.
190
258
191−Source
259+#### Source
192−------
193
260
194− ++ gth :: greater-than
261+ ++ gth
195 ~/ %gth
262 ~/ %gth
196− |= {a/@ b/@}
263+ |= [a=@ b=@]
197 ^- ?
264 ^- ?
198 !(lte a b)
265 !(lte a b)
199
266
200
267
201
268
202−Examples
269+#### Examples
203−--------
204
270
205 > (gth 'd' 'c')
271 > (gth 'd' 'c')
206 %.y
272 %.y
273+
207 > (gth ~h1 ~m61)
274 > (gth ~h1 ~m61)
208 %.n
275 %.n
209
276
277+ > (gth 'steak' 'brisket')
278+ %.n
210
279
211
280
212***
281***
@@ -216,41 +285,53 @@ Less-than/equal
216
285
217Tests whether `a` is less than or equal to `b`.
286Tests whether `a` is less than or equal to `b`.
218
287
219−Accepts
288+#### Accepts
220−-------
221
289
222`a` is an atom.
290`a` is an atom.
223
291
224`b` is an atom.
292`b` is an atom.
225
293
226−Produces
294+#### Produces
227−--------
228
295
229−A boolean.
296+A flag.
230
297
231−Source
298+#### Source
232−------
233
299
234− ++ lte :: less-equal
300+ ++ lte
235 ~/ %lte
301 ~/ %lte
236− |= {a/@ b/@}
302+ |= [a=@ b=@]
237 |(=(a b) (lth a b))
303 |(=(a b) (lth a b))
238
304
239− ::
240
305
241−Examples
306+#### Examples
242−--------
243
307
244 > (lte 4 5)
308 > (lte 4 5)
245 %.y
309 %.y
310+
246 > (lte 5 4)
311 > (lte 5 4)
247 %.n
312 %.n
313+
248 > (lte 5 5)
314 > (lte 5 5)
249 %.y
315 %.y
316+
250 > (lte 0 0)
317 > (lte 0 0)
251 %.y
318 %.y
252
319
253
320
321+ > (lte 'a' 'b')
322+ %.y
323+ > `@`'a'
324+ 97
325+ > `@`'b'
326+ 98
327+
328+ > (lte 'abraham' 'bob')
329+ %.n
330+
331+ > (lte ~m61 ~h1)
332+ %.n
333+
334+
254
335
255***
336***
256### `++lth`
337### `++lth`
@@ -259,24 +340,21 @@ Less-than
259
340
260Tests whether `a` is less than `b`.
341Tests whether `a` is less than `b`.
261
342
262−Accepts
343+#### Accepts
263−-------
264
344
265`a` is an atom.
345`a` is an atom.
266
346
267`b` is an atom.
347`b` is an atom.
268
348
269−Produces
349+#### Produces
270−--------
271
350
272−A boolean.
351+A flag.
273
352
274−Source
353+#### Source
275−------
276
354
277− ++ lth :: less-than
355+ ++ lth
278 ~/ %lth
356 ~/ %lth
279− |= {a/@ b/@}
357+ |= [a=@ b=@]
280 ^- ?
358 ^- ?
281 ?& !=(a b)
359 ?& !=(a b)
282 |-
360 |-
@@ -285,18 +363,30 @@ Source
285 $(a (dec a), b (dec b))
363 $(a (dec a), b (dec b))
286 == == ==
364 == == ==
287
365
288−Examples
366+#### Examples
289−--------
290
367
291 > (lth 4 5)
368 > (lth 4 5)
292 %.y
369 %.y
370+
293 > (lth 5 4)
371 > (lth 5 4)
294 %.n
372 %.n
373+
295 > (lth 5 5)
374 > (lth 5 5)
296 %.n
375 %.n
376+
297 > (lth 5 0)
377 > (lth 5 0)
298 %.n
378 %.n
299
379
380+ > (lth 'a' 'b')
381+ %.y
382+ > `@`'a'
383+ 97
384+ > `@`'b'
385+ 98
386+
387+ > (lth 'abraham' 'bob')
388+ %.n
389+
300
390
301***
391***
302### `++max`
392### `++max`
@@ -305,39 +395,50 @@ Maximum
305
395
306Computes the greater of `a` and `b`.
396Computes the greater of `a` and `b`.
307
397
308−Accepts
398+#### Accepts
309−-------
310
399
311`a` is an atom.
400`a` is an atom.
312
401
313`b` is an atom.
402`b` is an atom.
314
403
315−Produces
404+#### Produces
316−--------
317
405
318An atom.
406An atom.
319
407
320−Source
408+#### Source
321−------
322
409
323− ++ max :: maximum
410+ ++ max
324 ~/ %max
411 ~/ %max
325− |= {a/@ b/@}
412+ |= [a=@ b=@]
326 ^- @
413 ^- @
327 ?: (gth a b) a
414 ?: (gth a b) a
328 b
415 b
329
416
330−Examples
417+#### Examples
331−--------
332
418
333 > (max 10 100)
419 > (max 10 100)
334 100
420 100
421+
335 > (max 10.443 9)
422 > (max 10.443 9)
336 10.443
423 10.443
424+
337− > (max 0 1)
425+ > (max 1 1)
338 1
426 1
339
427
428+ > (max 'abraham' 'bob')
429+ 30.787.873.400.840.801
430+
431+ > `@t`(max 'abraham' 'bob')
432+ 'abraham'
433+
434+ > `@t`(max 'abraham' 'benjamin')
435+ 'benjamin'
340
436
437+ > `@dr`(max ~m6 ~h1)
438+ ~h1
439+
440+ >`@ux`(max 0xe1 0x1e)
441+ 0xe1
341
442
342***
443***
343### `++min`
444### `++min`
@@ -346,37 +447,47 @@ Minimum
346
447
347Computes the lesser of `a` and `b`.
448Computes the lesser of `a` and `b`.
348
449
349−Accepts
450+#### Accepts
350−-------
351
451
352`a` is an atom.
452`a` is an atom.
353
453
354`b` is an atom.
454`b` is an atom.
355
455
356−Produces
456+#### Produces
357−--------
358
457
359An atom.
458An atom.
360
459
361−Source
460+#### Source
362−------
363
461
364− ++ min :: minimum
462+ ++ min
365 ~/ %min
463 ~/ %min
366− |= {a/@ b/@}
464+ |= [a=@ b=@]
367 ^- @
465 ^- @
368 ?: (lth a b) a
466 ?: (lth a b) a
369 b
467 b
370−
468+
371−Examples
469+#### Examples
372−--------
373
470
374 > (min 10 100)
471 > (min 10 100)
375 10
472 10
473+
376 > (min 10.443 9)
474 > (min 10.443 9)
377 9
475 9
476+
378− > (min 0 1)
477+ > (min 1 1)
379− 0
478+ 1
479+
480+ > (min 'abraham' 'bob')
481+ 6.451.042
482+
483+ > `@t`(min 'abraham' 'bob')
484+ 'bob'
485+
486+ > `@t`(min 'abraham' 'benjamin')
487+ 'abraham'
488+
489+ > `@dr`(min ~m6 ~h1)
490+ ~m6
380
491
381
492
382
493
@@ -387,37 +498,47 @@ Modulus
387
498
388Computes the remainder of dividing `a` by `b`.
499Computes the remainder of dividing `a` by `b`.
389
500
390−Accepts
501+#### Accepts
391−-------
392
502
393`a` is an atom.
503`a` is an atom.
394
504
395`b` is an atom.
505`b` is an atom.
396
506
397−Produces
507+#### Produces
398−--------
399
508
400An atom.
509An atom.
401
510
402−Source
511+#### Source
403−------
404
512
405− ++ mod :: remainder
513+ ++ mod
406 ~/ %mod
514 ~/ %mod
407 |: [a=`@`1 b=`@`1]
515 |: [a=`@`1 b=`@`1]
408 ^- @
516 ^- @
409 ?< =(0 b)
517 ?< =(0 b)
410 (sub a (mul b (div a b)))
518 (sub a (mul b (div a b)))
411−
412
519
520+
413−Examples
521+#### Examples
414−--------
522+
415
523
416 > (mod 5 2)
524 > (mod 5 2)
417 1
525 1
526+
418 > (mod 5 5)
527 > (mod 5 5)
419 0
528 0
420
529
530+ > (mod 2 5)
531+ 2
532+
533+ > (mod 40 20)
534+ 0
535+
536+ > `@`'c'
537+ 99
538+ >`@`'a'
539+ 97
540+ > (mod 'c' 'a')
541+ 2
421
542
422
543
423***
544***
@@ -427,22 +548,19 @@ Multiply
427
548
428Multiplies `a` by `b`.
549Multiplies `a` by `b`.
429
550
430−Accepts
551+#### Accepts
431−-------
432
552
433`a` is an atom.
553`a` is an atom.
434
554
435`b` is an atom.
555`b` is an atom.
436
556
437−Produces
557+#### Produces
438−--------
439
558
440An atom.
559An atom.
441
560
442−Source
561+#### Source
443−------
444
562
445− ++ mul :: multiply
563+ ++ mul
446 ~/ %mul
564 ~/ %mul
447 |: [a=`@`1 b=`@`1]
565 |: [a=`@`1 b=`@`1]
448 ^- @
566 ^- @
@@ -450,15 +568,25 @@ Source
450 |-
568 |-
451 ?: =(0 a) c
569 ?: =(0 a) c
452 $(a (dec a), c (add b c))
570 $(a (dec a), c (add b c))
453−
571+
454−Examples
572+#### Examples
455−--------
456
573
457 > (mul 3 4)
574 > (mul 3 4)
458− 12
575+ 12
576+
459− > (mul 0 1)
577+ > (mul 0 1)
460 0
578 0
461
579
580+ > `@`'a'
581+ 97
582+ > `@`'b'
583+ 98
584+ > (mul 'a' 'b')
585+ 9.506
586+
587+ >`@ux`(mul 0x1f 0xe)
588+ 0x1b2
589+
462
590
463
591
464***
592***
@@ -468,42 +596,54 @@ Subtract
468
596
469Subtracts `b` from `a`.
597Subtracts `b` from `a`.
470
598
471−Accepts
599+#### Accepts
472−-------
473
600
474`a` is an atom.
601`a` is an atom.
475
602
476`b` is an atom.
603`b` is an atom.
477
604
478−Produces
605+#### Produces
479−--------
480
606
481An atom.
607An atom.
482
608
483−Source
609+#### Source
484−------
485
610
486− ++ sub :: subtract
611+ ++ sub
487 ~/ %sub
612 ~/ %sub
488− |= [a/@ b/@]
613+ |= [a=@ b=@]
489− ~| %subtract-underflow
614+ ~_ leaf+"subtract-underflow"
490 ^- @
615 ^- @
491 ?: =(0 b) a
616 ?: =(0 b) a
492 $(a (dec a), b (dec b))
617 $(a (dec a), b (dec b))
493
618
619+
620+
494−Examples
621+#### Examples
495−--------
496
622
497 > (sub 10 5)
623 > (sub 10 5)
498 5
624 5
625+
499 > (sub 243 44)
626 > (sub 243 44)
500 199
627 199
628+
501 > (sub 5 0)
629 > (sub 5 0)
502 5
630 5
631+
503 > (sub 0 5)
632 > (sub 0 5)
504 ! subtract-underflow
633 ! subtract-underflow
505 ! exit
634 ! exit
506
635
636+ > (sub 'c' 'a')
637+ 2
638+ > `@`'c'
639+ 99
640+ > `@`'a'
641+ 97
642+
643+ > (sub 0x1f 0xe)
644+ 17
645+ > `@ux`(sub 0x1f 0xe)
646+ 0x11
507
647
508
648
509***
649***