on master help sign in
Merge pull request #264 from urbit/rmariani-patch-4

Updated syntax for 1a

commit8d7cd25ab8564aa524b52ca6a2c750aced58ece2 authorJoshua Reagan <joshuareagan@users.noreply.github.com> dateFri 8 Jun 2018, 08:06 (8 years ago) parente8793ab3578156
1 file changed+276−136
docs/hoon/library/1a.md+276−136
docs/hoon/library/1a.md+276−136
@@ -10,38 +10,48 @@ Add
1010
1111Produces the sum of `a` and `b`.
1212
13−Accepts
14−-------
13+#### Accepts
1514
1615`a` is an atom.
1716
1817`b` is an atom.
1918
20−Produces
21−--------
19+#### Produces
2220
2321An atom.
2422
25−Source
26−------
23+#### Source
2724
28− ++ add :: add
25+ ++ add
2926 ~/ %add
30− |= [a/@ b/@]
27+ |= [a=@ b=@]
3128 ^- @
3229 ?: =(0 a) b
3330 $(a (dec a), b +(b))
3431
35−Examples
36−--------
32+#### Examples
3733
3834 > (add 2 2)
3935 4
36+
4037 > (add 1 1.000.000)
4138 1.000.001
39+
4240 > (add 1.333 (mul 2 2))
4341 1.337
4442
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+
4555***
4656### `++dec`
4757
@@ -49,22 +59,19 @@ Decrement
4959
5060Decrements `a` by `1`.
5161
52−Accepts
53−-------
62+#### Accepts
5463
5564`a` is an atom.
5665
57−Produces
58−--------
66+#### Produces
5967
6068An atom.
6169
62−Source
63−------
70+#### Source
6471
65− ++ dec :: decrement
72+ ++ dec
6673 ~/ %dec
67− |= a/@
74+ |= a=@
6875 ~| %decrement-underflow
6976 ?< =(0 a)
7077 =+ b=0
@@ -72,15 +79,25 @@ Source
7279 ?: =(a +(b)) b
7380 $(b +(b))
7481
75−Examples
76−--------
82+#### Examples
7783
7884 > (dec 7)
7985 6
86+
8087 > (dec 0)
8188 ! decrement-underflow
8289 ! exit
8390
91+ > (dec 'b')
92+ 97
93+ > `@t`(dec 'b')
94+ 'a'
95+
96+ > (dec 0xc)
97+ 11
98+ > `@ux`(dec 0xc)
99+ 0xb
100+
84101
85102
86103***
@@ -88,82 +105,135 @@ Examples
88105
89106Divide
90107
91−Computes `a` divided by `b`.
108+Computes `a` divided by `b` without remainder.
92109
93−Accepts
94−-------
110+#### Accepts
95111
96112`a` is an atom.
97113
98114`b` is an atom.
99115
100−Produces
101−--------
116+#### Produces
102117
103118An atom.
104119
105−Source
106−------
120+#### Source
107121
108− ++ div :: divide
122+ ++ div
109123 ~/ %div
110− |= [a/@ b/@]
124+ |: [a=`@`1 b=`@`1]
111125 ^- @
112− ~| 'div'
126+ ~_ leaf+"divide-by-zero"
113127 ?< =(0 b)
114128 =+ c=0
115129 |-
116130 ?: (lth a b) c
117131 $(a (sub a b), c +(c))
118− ::
119132
120−Examples
121−--------
133+
134+#### Examples
135+
122136
123137 > (div 4 2)
124138 2
139+
125140 > (div 17 8)
126141 2
142+
127143 > (div 20 30)
128144 0
129145
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
130202
131203***
132204### `++gte`
133205
134206Greater-than/equal
135207
136−Tests whether `a` is greater than a number `b`.
208+Tests whether `a` is greater than or equal to `b`.
137209
138−Accepts
139−-------
210+#### Accepts
140211
141212`a` is an atom.
142213
143214`b` is an atom.
144215
145−Produces
146−--------
216+#### Produces
147217
148−A boolean.
218+A flag.
149219
150−Source
151−------
220+#### Source
152221
153− ++ gte :: greater-equal
222+ ++ gte
154223 ~/ %gte
155− |= {a/@ b/@}
224+ |= [a=@ b=@]
156225 ^- ?
157226 !(lth a b)
158227
159228
160−Examples
161−--------
229+#### Examples
162230
163231 > (gte 100 10)
164232 %.y
233+
165234 > (gte 4 4)
166235 %.y
236+
167237 > (gte 3 4)
168238 %.n
169239
@@ -176,37 +246,36 @@ Greater-than
176246
177247Tests whether `a` is greater than `b`.
178248
179−Accepts
180−-------
249+#### Accepts
181250
182251`a` is an atom.
183252
184253`b` is an atom.
185254
186−Produces
187−--------
255+#### Produces
188256
189−A boolean.
257+A flag.
190258
191−Source
192−------
259+#### Source
193260
194− ++ gth :: greater-than
261+ ++ gth
195262 ~/ %gth
196− |= {a/@ b/@}
263+ |= [a=@ b=@]
197264 ^- ?
198265 !(lte a b)
199266
200267
201268
202−Examples
203−--------
269+#### Examples
204270
205271 > (gth 'd' 'c')
206272 %.y
273+
207274 > (gth ~h1 ~m61)
208275 %.n
209276
277+ > (gth 'steak' 'brisket')
278+ %.n
210279
211280
212281***
@@ -216,41 +285,53 @@ Less-than/equal
216285
217286Tests whether `a` is less than or equal to `b`.
218287
219−Accepts
220−-------
288+#### Accepts
221289
222290`a` is an atom.
223291
224292`b` is an atom.
225293
226−Produces
227−--------
294+#### Produces
228295
229−A boolean.
296+A flag.
230297
231−Source
232−------
298+#### Source
233299
234− ++ lte :: less-equal
300+ ++ lte
235301 ~/ %lte
236− |= {a/@ b/@}
302+ |= [a=@ b=@]
237303 |(=(a b) (lth a b))
238304
239− ::
240305
241−Examples
242−--------
306+#### Examples
243307
244308 > (lte 4 5)
245309 %.y
310+
246311 > (lte 5 4)
247312 %.n
313+
248314 > (lte 5 5)
249315 %.y
316+
250317 > (lte 0 0)
251318 %.y
252319
253320
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+
254335
255336***
256337### `++lth`
@@ -259,24 +340,21 @@ Less-than
259340
260341Tests whether `a` is less than `b`.
261342
262−Accepts
263−-------
343+#### Accepts
264344
265345`a` is an atom.
266346
267347`b` is an atom.
268348
269−Produces
270−--------
349+#### Produces
271350
272−A boolean.
351+A flag.
273352
274−Source
275−------
353+#### Source
276354
277− ++ lth :: less-than
355+ ++ lth
278356 ~/ %lth
279− |= {a/@ b/@}
357+ |= [a=@ b=@]
280358 ^- ?
281359 ?& !=(a b)
282360 |-
@@ -285,18 +363,30 @@ Source
285363 $(a (dec a), b (dec b))
286364 == == ==
287365
288−Examples
289−--------
366+#### Examples
290367
291368 > (lth 4 5)
292369 %.y
370+
293371 > (lth 5 4)
294372 %.n
373+
295374 > (lth 5 5)
296375 %.n
376+
297377 > (lth 5 0)
298378 %.n
299379
380+ > (lth 'a' 'b')
381+ %.y
382+ > `@`'a'
383+ 97
384+ > `@`'b'
385+ 98
386+
387+ > (lth 'abraham' 'bob')
388+ %.n
389+
300390
301391***
302392### `++max`
@@ -305,39 +395,50 @@ Maximum
305395
306396Computes the greater of `a` and `b`.
307397
308−Accepts
309−-------
398+#### Accepts
310399
311400`a` is an atom.
312401
313402`b` is an atom.
314403
315−Produces
316−--------
404+#### Produces
317405
318406An atom.
319407
320−Source
321−------
408+#### Source
322409
323− ++ max :: maximum
410+ ++ max
324411 ~/ %max
325− |= {a/@ b/@}
412+ |= [a=@ b=@]
326413 ^- @
327414 ?: (gth a b) a
328415 b
329416
330−Examples
331−--------
417+#### Examples
332418
333419 > (max 10 100)
334420 100
421+
335422 > (max 10.443 9)
336423 10.443
337− > (max 0 1)
424+
425+ > (max 1 1)
338426 1
339427
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'
340436
437+ > `@dr`(max ~m6 ~h1)
438+ ~h1
439+
440+ >`@ux`(max 0xe1 0x1e)
441+ 0xe1
341442
342443***
343444### `++min`
@@ -346,37 +447,47 @@ Minimum
346447
347448Computes the lesser of `a` and `b`.
348449
349−Accepts
350−-------
450+#### Accepts
351451
352452`a` is an atom.
353453
354454`b` is an atom.
355455
356−Produces
357−--------
456+#### Produces
358457
359458An atom.
360459
361−Source
362−------
460+#### Source
363461
364− ++ min :: minimum
462+ ++ min
365463 ~/ %min
366− |= {a/@ b/@}
464+ |= [a=@ b=@]
367465 ^- @
368466 ?: (lth a b) a
369467 b
370−
371−Examples
372−--------
468+
469+#### Examples
373470
374471 > (min 10 100)
375472 10
473+
376474 > (min 10.443 9)
377475 9
378− > (min 0 1)
379− 0
476+
477+ > (min 1 1)
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
380491
381492
382493
@@ -387,37 +498,47 @@ Modulus
387498
388499Computes the remainder of dividing `a` by `b`.
389500
390−Accepts
391−-------
501+#### Accepts
392502
393503`a` is an atom.
394504
395505`b` is an atom.
396506
397−Produces
398−--------
507+#### Produces
399508
400509An atom.
401510
402−Source
403−------
511+#### Source
404512
405− ++ mod :: remainder
513+ ++ mod
406514 ~/ %mod
407515 |: [a=`@`1 b=`@`1]
408516 ^- @
409517 ?< =(0 b)
410518 (sub a (mul b (div a b)))
411−
412519
413−Examples
414−--------
520+
521+#### Examples
522+
415523
416524 > (mod 5 2)
417525 1
526+
418527 > (mod 5 5)
419528 0
420529
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
421542
422543
423544***
@@ -427,22 +548,19 @@ Multiply
427548
428549Multiplies `a` by `b`.
429550
430−Accepts
431−-------
551+#### Accepts
432552
433553`a` is an atom.
434554
435555`b` is an atom.
436556
437−Produces
438−--------
557+#### Produces
439558
440559An atom.
441560
442−Source
443−------
561+#### Source
444562
445− ++ mul :: multiply
563+ ++ mul
446564 ~/ %mul
447565 |: [a=`@`1 b=`@`1]
448566 ^- @
@@ -450,15 +568,25 @@ Source
450568 |-
451569 ?: =(0 a) c
452570 $(a (dec a), c (add b c))
453−
454−Examples
455−--------
571+
572+#### Examples
456573
457574 > (mul 3 4)
458− 12
459− > (mul 0 1)
575+ 12
576+
577+ > (mul 0 1)
460578 0
461579
580+ > `@`'a'
581+ 97
582+ > `@`'b'
583+ 98
584+ > (mul 'a' 'b')
585+ 9.506
586+
587+ >`@ux`(mul 0x1f 0xe)
588+ 0x1b2
589+
462590
463591
464592***
@@ -468,42 +596,54 @@ Subtract
468596
469597Subtracts `b` from `a`.
470598
471−Accepts
472−-------
599+#### Accepts
473600
474601`a` is an atom.
475602
476603`b` is an atom.
477604
478−Produces
479−--------
605+#### Produces
480606
481607An atom.
482608
483−Source
484−------
609+#### Source
485610
486− ++ sub :: subtract
611+ ++ sub
487612 ~/ %sub
488− |= [a/@ b/@]
489− ~| %subtract-underflow
613+ |= [a=@ b=@]
614+ ~_ leaf+"subtract-underflow"
490615 ^- @
491616 ?: =(0 b) a
492617 $(a (dec a), b (dec b))
493618
494−Examples
495−--------
619+
620+
621+#### Examples
496622
497623 > (sub 10 5)
498624 5
625+
499626 > (sub 243 44)
500627 199
628+
501629 > (sub 5 0)
502630 5
631+
503632 > (sub 0 5)
504633 ! subtract-underflow
505634 ! exit
506635
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
507647
508648
509649***