on master help sign in
Merge pull request #763 from urbit/add-rev-to-stdlib

add +rev to stdlib

commit531ec9a086e98226bef20c149304dc9b889ee28d authorpoprox <51337059+drbeefsupreme@users.noreply.github.com> dateMon 16 Aug 2021, 12:19 (5 years ago) parent8bd0b6d53a9932
2 files changed+69
content/docs/hoon/reference/stdlib/2c.md+67 content/docs/hoon/reference/stdlib/table-of-contents.md+2
content/docs/hoon/reference/stdlib/2c.md+67
@@ -584,6 +584,73 @@ An atom.
584584 'abcd'
585585```
586586
587+---
588+### `++rev`
589+
590+Reverses block order, accounting for leading zeroes.
591+
592+Produces an atom from the bits of `dat` in reverse order according to a block
593+size `boz` and a size `len`.
594+
595+If the total size is less than the length of `dat`, then only the first
596+bits of `dat` up to the total size will be taken and reversed. If the total size
597+is longer, trailing zeroes will be added.
598+
599+#### Accepts
600+
601+`boz` is a block size with optional block count (see
602+ [`$bloq`](/docs/hoon/reference/stdlib/1c#bloq)).
603+
604+`len` is a `@ud` of the number of blocks of size `boz` to be reversed.
605+
606+`dat` is an atom.
607+
608+#### Produces
609+
610+An atom.
611+
612+#### Source
613+
614+```hoon
615+++ rev
616+ ~/ %rev
617+ |= [boz=bloq len=@ud dat=@]
618+ ^- @
619+ =. dat (end [boz len] dat)
620+ %+ lsh
621+ [boz (sub len (met boz dat))]
622+ (swp boz dat)
623+```
624+
625+#### Examples
626+
627+```
628+> =a 0b1111.0000.1111.1010.0011
629+
630+> `@ub`(rev 0 20 a)
631+0b1100.0101.1111.0000.1111
632+
633+> `@ub`(rev 0 12 a)
634+0b1100.0101.1111
635+
636+> `@ub`(rev 2 5 a)
637+0b11.1010.1111.0000.1111
638+
639+> `@ub`(rev 2 4 a)
640+0b11.1010.1111.0000
641+
642+> `@ub`(rev 2 6 a)
643+0b11.1010.1111.0000.1111.0000
644+
645+> (rev 1 10 1.000)
646+179.200
647+
648+> (rev 2 5 1.000)
649+582.400
650+
651+> (rev 1 5 1.000)
652+175
653+```
587654
588655---
589656### `++rip`
content/docs/hoon/reference/stdlib/table-of-contents.md+2
@@ -504,6 +504,7 @@ Can be navigated [alphabetically](#alphabetical) or [by section](#by-section).
504504<a class="tooltip" href='/docs/hoon/reference/stdlib/2c/#rep' title="Assemble single"><code>++rep</code></a>
505505<a class="tooltip" href='/docs/hoon/reference/stdlib/2i/#repby' title="Replace by product (map)"><code>++rep:by</code></a>
506506<a class="tooltip" href='/docs/hoon/reference/stdlib/2h/#repin' title="Accumulate elements (set)"><code>++rep:in</code></a>
507+<a class="tooltip" href='/docs/hoon/reference/stdlib/2c/#rev' title="Reverse"><code>++rev</code></a>
507508<a class="tooltip" href='/docs/hoon/reference/stdlib/4b/#rfat' title="(Undocumented)"><code>++rf:at</code></a>
508509<a class="tooltip" href='/docs/hoon/reference/stdlib/2i/#ribby' title="Replace values with accumulator (map)"><code>++rib:by</code></a>
509510<a class="tooltip" href='/docs/hoon/reference/stdlib/4c/#rigre' title="Wrap tape in / (tank)"><code>++rig:re</code></a>
@@ -918,6 +919,7 @@ Can be navigated [alphabetically](#alphabetical) or [by section](#by-section).
918919<a class="tooltip" href='/docs/hoon/reference/stdlib/2c/#rap' title="Assemble nonzero"><code>++rap</code></a>
919920<a class="tooltip" href='/docs/hoon/reference/stdlib/2c/#rep' title="Assemble single"><code>++rep</code></a>
920921<a class="tooltip" href='/docs/hoon/reference/stdlib/2c/#rip' title="Disassemble"><code>++rip</code></a>
922+<a class="tooltip" href='/docs/hoon/reference/stdlib/2c/#rev' title="Reverse"><code>++rev</code></a>
921923<a class="tooltip" href='/docs/hoon/reference/stdlib/2c/#rsh' title="Rightshift"><code>++rsh</code></a>
922924<a class="tooltip" href='/docs/hoon/reference/stdlib/2c/#swp' title="Reverse block order"><code>++swp</code></a>
923925<a class="tooltip" href='/docs/hoon/reference/stdlib/2c/#xeb' title="Binary logarithm"><code>++xeb</code></a>