on master help sign in
Merge pull request #1039 from krendil/master
a9b87cbpoprox
hoon/reference/stdlib/1c.md+39−1
@@ -4,7 +4,45 @@ weight = 3
4template = "doc.html"
4template = "doc.html"
5+++
5+++
6
6
7+### `$bite`
8+
9+Atom slice specifier.
10+
11+Either a single atom representing block size, or a cell containing a block size
12+and an atom representing the number of blocks, called `step`. If `step` is not
13+supplied, it defaults to a value of 1.
14+
15+#### Source
16+
17+```hoon
18+ +$ bite $@(bloq [=bloq =step])
19+```
20+
21+#### Examples
22+
23+```
24+ :: ++end gets the least significant bits of an atom.
25+
26+ > (end [1 1] 255)
27+ 3
28+
29+ > (end 1 255)
30+ 3
31+
32+ > (end 3 255)
33+ 255
34+
35+ > (end 3 65.535)
36+ 255
37+
38+ > (end [3 2] 65.535)
39+ 65.535
40+
41+ > (end [3 0] 65.535)
42+ 0
43+```
44+
7−### `++bloq`
45+### `$bloq`
8
46
9Blocksize
47Blocksize
10
48
hoon/reference/stdlib/2c.md+165−52
@@ -228,16 +228,16 @@ An atom.
228
228
229Tail
229Tail
230
230
231−Produces an atom by taking the last `b` blocks of size `a` from `c`.
231+Produces an atom by taking the last `step` blocks of size `bloq` from `b`.
232
232
233#### Accepts
233#### Accepts
234
234
235+`a` is an atom slice specifier (see [`++bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
235−`a` is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md)).
236+which is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
237+with optional block count.
236
238
237`b` is an atom.
239`b` is an atom.
238
240
239−`c` is an atom.
240−
241#### Produces
241#### Produces
242
242
243An atom.
243An atom.
@@ -248,44 +248,48 @@ An atom.
248```hoon
248```hoon
249 ++ end
249 ++ end
250 ~/ %end
250 ~/ %end
251− |= [a=bloq b=@u c=@]
251+ |= [a=bite b=@]
252+ =/ [=bloq =step] ?^(a a [a *step])
252− (mod c (bex (mul (bex a) b)))
253+ (mod b (bex (mul (bex bloq) step)))
253```
254```
254
255
255#### Examples
256#### Examples
256
257
257```
258```
258− > (end 2 2 255)
259+ > (end [2 2] 255)
260+ 255
261+
262+ > (end [3 1] 255)
259 255
263 255
260
264
261− > (end 3 1 255)
265+ > (end 3 255)
262 255
266 255
263
267
264− > (end 3 1 256)
268+ > (end 3 256)
265 0
269 0
266
270
267 > `@ub`12 :: @ub is the binary aura
271 > `@ub`12 :: @ub is the binary aura
268 0b1100
272 0b1100
269
273
270− > `@ub`(end 0 3 12)
274+ > `@ub`(end [0 3] 12)
271 0b100
275 0b100
272
276
273− > (end 0 3 12)
277+ > (end [0 3] 12)
274 4
278 4
275
279
276− > `@ub`(end 1 3 12)
280+ > `@ub`(end [1 3] 12)
277 0b1100
281 0b1100
278
282
279− > (end 1 3 12)
283+ > (end [1 3] 12)
280 12
284 12
281
285
282 > `@ux`'abc' :: @ux is the hexademical aura
286 > `@ux`'abc' :: @ux is the hexademical aura
283 0x63.6261
287 0x63.6261
284
288
285− > `@ux`(end 3 2 'abc')
289+ > `@ux`(end [3 2] 'abc')
286 0x6261
290 0x6261
287
291
288− > `@t`(end 3 2 'abc') :: @t is the cord aura
292+ > `@t`(end [3 2] 'abc') :: @t is the cord aura
289 'ab'
293 'ab'
290```
294```
291
295
@@ -347,16 +351,16 @@ An atom.
347
351
348Left-shift
352Left-shift
349
353
350−Produces an atom by left-shifting `c` by `b` blocks of size `a`.
354+Produces an atom by left-shifting `b` by `step` blocks of size `bloq`.
351
355
352#### Accepts
356#### Accepts
353
357
358+`a` is an atom slice specifier (see [`++bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
354−`a` is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md)).
359+which is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
360+with optional block count.
355
361
356`b` is an atom.
362`b` is an atom.
357
363
358−`c` is an atom.
359−
360#### Produces
364#### Produces
361
365
362An atom.
366An atom.
@@ -366,8 +370,9 @@ An atom.
366```hoon
370```hoon
367 ++ lsh
371 ++ lsh
368 ~/ %lsh
372 ~/ %lsh
369− |= [a=bloq b=@u c=@]
373+ |= [a=bite b=@]
374+ =/ [=bloq =step] ?^(a a [a *step])
370− (mul (bex (mul (bex a) b)) c)
375+ (mul b (bex (mul (bex bloq) step)))
371```
376```
372
377
373#### Examples
378#### Examples
@@ -376,19 +381,22 @@ An atom.
376 > `@ub`1 :: @ub is the binary aura
381 > `@ub`1 :: @ub is the binary aura
377 0b1
382 0b1
378
383
379− > `@ub`(lsh 0 1 1)
384+ > `@ub`(lsh [0 1] 1)
380 0b10
385 0b10
381
386
382− > (lsh 0 1 1)
387+ > (lsh [0 1] 1)
388+ 2
389+
390+ > (lsh 0 1)
383 2
391 2
384
392
385 > `@ub`255
393 > `@ub`255
386 0b1111.1111
394 0b1111.1111
387
395
388− > `@ub`(lsh 3 1 255)
396+ > `@ub`(lsh [3 1] 255)
389 0b1111.1111.0000.0000
397 0b1111.1111.0000.0000
390
398
391− > (lsh 3 1 255)
399+ > (lsh [3 1] 255)
392 65.280
400 65.280
393```
401```
394
402
@@ -509,7 +517,9 @@ Produces an atom by assembling a list of atoms `b` using block size `a`.
509
517
510#### Accepts
518#### Accepts
511
519
520+`a` is an atom slice specifier (see [`$bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
512−`a` is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md)).
521+which is a block size (see [`$bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
522+with optional block count.
513
523
514`b` is a list of atoms.
524`b` is a list of atoms.
515
525
@@ -522,12 +532,13 @@ An atom.
522```hoon
532```hoon
523 ++ rep
533 ++ rep
524 ~/ %rep
534 ~/ %rep
525− |= [a=bloq b=(list @)]
535+ |= [a=bite b=(list @)]
536+ =/ [=bloq =step] ?^(a a [a *step])
537+ =| i=@ud
526− ^- @
538+ |- ^- @
527− =+ c=0
528− |-
529− ?~ b 0
539+ ?~ b 0
530− (add (lsh a c (end a 1 i.b)) $(c +(c), b t.b))
540+ %+ add $(i +(i), b t.b)
541+ (lsh [bloq (mul step i)] (end [bloq step] i.b))
531```
542```
532
543
533#### Examples
544#### Examples
@@ -548,8 +559,11 @@ An atom.
548 > `@ub`8
559 > `@ub`8
549 0b1000
560 0b1000
550
561
551− > (rep 0 [0 1 0 0 ~])
562+ > `@ub`(rep 0 [1 0 1 0 ~])
552− 2
563+ 0b101
564+
565+ > `@ub`(rep 0 [1 2 3 4 ~])
566+ 0b101
553
567
554 > (rep 0 [0 1 0 1 ~])
568 > (rep 0 [0 1 0 1 ~])
555 10
569 10
@@ -562,6 +576,12 @@ An atom.
562
576
563 > `@ub`(rep 3 [12 166 8 34 ~])
577 > `@ub`(rep 3 [12 166 8 34 ~])
564 0b10.0010.0000.1000.1010.0110.0000.1100
578 0b10.0010.0000.1000.1010.0110.0000.1100
579+
580+ > `*`"abcd"
581+ [97 98 99 100 0]
582+
583+ > `@t`(rep 3 "abcd") :: @t is the text aura
584+ 'abcd'
565```
585```
566
586
567
587
@@ -574,7 +594,9 @@ Produces a list of atoms from the bits of `b` using block size `a`.
574
594
575#### Accepts
595#### Accepts
576
596
597+`a` is an atom slice specifier (see [`$bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
577−`a` is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md)).
598+which is a block size (see [`$bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
599+with optional block count.
578
600
579`b` is an atom.
601`b` is an atom.
580
602
@@ -587,10 +609,10 @@ A list of atoms.
587```hoon
609```hoon
588 ++ rip
610 ++ rip
589 ~/ %rip
611 ~/ %rip
590− |= [a=bloq b=@]
612+ |= [a=bite b=@]
591 ^- (list @)
613 ^- (list @)
592 ?: =(0 b) ~
614 ?: =(0 b) ~
593− [(end a 1 b) $(b (rsh a 1 b))]
615+ [(end a b) $(b (rsh a b))]
594```
616```
595
617
596#### Examples
618#### Examples
@@ -622,6 +644,9 @@ A list of atoms.
622
644
623 > (rip 3 256)
645 > (rip 3 256)
624 ~[0 1]
646 ~[0 1]
647+
648+ > `tape`(rip 3 'abcd')
649+ "abcd"
625```
650```
626
651
627
652
@@ -630,16 +655,16 @@ A list of atoms.
630
655
631Right-shift
656Right-shift
632
657
633−Right-shifts `c` by `b` blocks of size `a`, producing an atom.
658+Right-shifts `b` by `step` blocks of size `bloq`, producing an atom.
634
659
635#### Accepts
660#### Accepts
636
661
662+`a` is an atom slice specifier (see [`$bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
637−`a` is a block size (see [`++bloq`](@/docs/hoon/reference/stdlib/1c.md)).
663+which is a block size (see [`$bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
664+with optional block count.
638
665
639`b` is an atom.
666`b` is an atom.
640
667
641−`c` is an atom.
642−
643#### Produces
668#### Produces
644
669
645An atom.
670An atom.
@@ -649,8 +674,9 @@ An atom.
649```hoon
674```hoon
650 ++ rsh
675 ++ rsh
651 ~/ %rsh
676 ~/ %rsh
652− |= [a=bloq b=@u c=@]
677+ |= [a=bite b=@]
678+ =/ [=bloq =step] ?^(a a [a *step])
653− (div c (bex (mul (bex a) b)))
679+ (div b (bex (mul (bex bloq) step)))
654```
680```
655
681
656#### Examples
682#### Examples
@@ -659,38 +685,125 @@ An atom.
659 > `@ub`145 :: @ub is the binary aura
685 > `@ub`145 :: @ub is the binary aura
660 0b1001.0001
686 0b1001.0001
661
687
662− > `@ub`(rsh 1 1 145)
688+ > `@ub`(rsh [1 1] 145)
663 0b10.0100
689 0b10.0100
664
690
665− > (rsh 1 1 145)
691+ > (rsh [1 1] 145)
666 36
692 36
667
693
694+ > (rsh 1 145)
695+ 36
696+
668− > `@ub`(rsh 2 1 145)
697+ > `@ub`(rsh [2 1] 145)
669 0b1001
698 0b1001
670
699
671− > (rsh 2 1 145)
700+ > (rsh [2 1] 145)
672 9
701 9
673
702
674 > `@ub`10
703 > `@ub`10
675 0b1010
704 0b1010
676
705
677− > `@ub`(rsh 0 1 10)
706+ > `@ub`(rsh [0 1] 10)
678 0b101
707 0b101
679
708
680− > (rsh 0 1 10)
709+ > (rsh [0 1] 10)
681 5
710 5
682
711
683 > `@ux`'abc'
712 > `@ux`'abc'
684 0x63.6261
713 0x63.6261
685
714
686− > `@t`(rsh 3 1 'abc')
715+ > `@t`(rsh [3 1] 'abc')
687 'bc'
716 'bc'
688
717
689− > `@ux`(rsh 3 1 'abc')
718+ > `@ux`(rsh [3 1] 'abc')
690 0x6362
719 0x6362
691```
720```
692
721
693
722
723+---
724+### `++run`
725+
726+`++turn` into atom.
727+
728+Disassembles atom `b` into slices specified by `a`, applies `c` to each slice,
729+and reassembles the results back into an atom.
730+
731+#### Accepts
732+
733+`a` is an atom slice specifier (see [`$bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
734+which is a block size (see [`$bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
735+with optional block count.
736+
737+`b` is an atom.
738+
739+`c` is a gate that accepts an atom and produces an atom.
740+
741+#### Produces
742+
743+An atom.
744+
745+#### Source
746+
747+```hoon
748+ ++ run
749+ ~/ %run
750+ |= [a=bite b=@ c=$-(@ @)]
751+ (rep a (turn (rip a b) c))
752+```
753+
754+#### Examples
755+
756+```
757+ > `@ux`65.535 :: @ux is the hexadecimal aura
758+ 0xffff
759+
760+ > `@ux`(run 2 65.535 dec) :: dec is the decrement gate
761+ 0xeeee
762+```
763+
764+
765+---
766+### `++rut`
767+
768+`++turn` into list.
769+
770+Disassembles atom `b` into slices specified by `a`, applies `c` to each slice,
771+and assembles the results back into a.
772+
773+#### Accepts
774+
775+`a` is an atom slice specifier (see [`$bite`](@/docs/hoon/reference/stdlib/1c.md#bite)),
776+which is a block size (see [`$bloq`](@/docs/hoon/reference/stdlib/1c.md#bloq))
777+with optional block count.
778+
779+`b` is an atom.
780+
781+`c` is a gate that accepts an atom.
782+
783+#### Produces
784+
785+A list.
786+
787+#### Source
788+
789+```hoon
790+ ++ rut
791+ ~/ %rut
792+ |* [a=bite b=@ c=$-(@ *)]
793+ (turn (rip a b) c)
794+```
795+
796+#### Examples
797+
798+```
799+ > `@ux`65.535 :: @ux is the hexadecimal aura
800+ 0xffff
801+
802+ > `(list @ux)`(rut 2 65.535 dec) :: dec is the decrement gate
803+ ~[0xe 0xe 0xe 0xe]
804+```
805+
806+
694---
807---
695### `++swp`
808### `++swp`
696
809
@@ -1248,4 +1361,4 @@ An atom.
1248 44.464
1361 44.464
1249```
1362```
1250
1363
1251−---
1364+---
hoon/reference/stdlib/table-of-contents.md+4−2
@@ -68,9 +68,10 @@ Can be navigated [alphabetically](#alphabetical) or [by section](#by-section).
68<a class="tooltip" href='/docs/hoon/reference/stdlib/3b/#bit-rh' title="fn to half-precision float"><code>++bit:rh</code></a>
68<a class="tooltip" href='/docs/hoon/reference/stdlib/3b/#bit-rh' title="fn to half-precision float"><code>++bit:rh</code></a>
69<a class="tooltip" href='/docs/hoon/reference/stdlib/3b/#bit-rs' title="fn to single-precision float"><code>++bit:rs</code></a>
69<a class="tooltip" href='/docs/hoon/reference/stdlib/3b/#bit-rs' title="fn to single-precision float"><code>++bit:rs</code></a>
70<a class="tooltip" href='/docs/hoon/reference/stdlib/3b/#bit-rq' title="fn to quad-precision float"><code>++bit:rq</code></a>
70<a class="tooltip" href='/docs/hoon/reference/stdlib/3b/#bit-rq' title="fn to quad-precision float"><code>++bit:rq</code></a>
71+<a class="tooltip" href='/docs/hoon/reference/stdlib/1c/#bite' title="Atom slice specificier"><code>$bite</code></a>
71<a class="tooltip" href='/docs/hoon/reference/stdlib/4j/#bix-ab' title="Parse hex pair"><code>++bix:ab</code></a>
72<a class="tooltip" href='/docs/hoon/reference/stdlib/4j/#bix-ab' title="Parse hex pair"><code>++bix:ab</code></a>
72<a class="tooltip" href='/docs/hoon/reference/stdlib/4l/#bisk-so' title="Parse aura-atom pair"><code>++bisk:so</code></a>
73<a class="tooltip" href='/docs/hoon/reference/stdlib/4l/#bisk-so' title="Parse aura-atom pair"><code>++bisk:so</code></a>
73−<a class="tooltip" href='/docs/hoon/reference/stdlib/1c/#bloq' title="Blocksize"><code>++bloq</code></a>
74+<a class="tooltip" href='/docs/hoon/reference/stdlib/1c/#bloq' title="Blocksize"><code>$bloq</code></a>
74<a class="tooltip" href='/docs/hoon/reference/stdlib/2a/#bond' title="Replace null"><code>++bond</code></a>
75<a class="tooltip" href='/docs/hoon/reference/stdlib/2a/#bond' title="Replace null"><code>++bond</code></a>
75<a class="tooltip" href='/docs/hoon/reference/stdlib/4f/#boss' title="Parser modifier: LSB"><code>++boss</code></a>
76<a class="tooltip" href='/docs/hoon/reference/stdlib/4f/#boss' title="Parser modifier: LSB"><code>++boss</code></a>
76<a class="tooltip" href='/docs/hoon/reference/stdlib/2a/#both' title="Group unit values into pair"><code>++both</code></a>
77<a class="tooltip" href='/docs/hoon/reference/stdlib/2a/#both' title="Group unit values into pair"><code>++both</code></a>
@@ -835,7 +836,8 @@ Can be navigated [alphabetically](#alphabetical) or [by section](#by-section).
835
836
836### 1c: molds and mold builders
837### 1c: molds and mold builders
837
838
838−<a class="tooltip" href='/docs/hoon/reference/stdlib/1c/#bloq' title="Blocksize"><code>++bloq</code></a>
839+<a class="tooltip" href='/docs/hoon/reference/stdlib/1c/#bite' title="Atom slice specificier"><code>$bite</code></a>
840+<a class="tooltip" href='/docs/hoon/reference/stdlib/1c/#bloq' title="Blocksize"><code>$bloq</code></a>
839<a class="tooltip" href='/docs/hoon/reference/stdlib/1c/#each' title="Mold of fork between two types"><code>++each</code></a>
841<a class="tooltip" href='/docs/hoon/reference/stdlib/1c/#each' title="Mold of fork between two types"><code>++each</code></a>
840<a class="tooltip" href='/docs/hoon/reference/stdlib/1c/#gate' title="Function"><code>++gate</code></a>
842<a class="tooltip" href='/docs/hoon/reference/stdlib/1c/#gate' title="Function"><code>++gate</code></a>
841<a class="tooltip" href='/docs/hoon/reference/stdlib/1c/#list' title="Mold constructor (list)"><code>++list</code></a>
843<a class="tooltip" href='/docs/hoon/reference/stdlib/1c/#list' title="Mold constructor (list)"><code>++list</code></a>