Urbit Developers
  • Hoon

    • Overview
    • Cheat Sheet
    • Irregular forms
    • Hoon Errors
    • Hoon Style Guide
    • Basic Types
    • Advanced Types
    • Auras
    • Standard Library

      • 1a: Basic Arithmetic
      • 1b: Tree Addressing
      • 1c: Molds and Mold-Builders
      • 2a: Unit Logic
      • 2b: List Logic
      • 2c: Bit Arithmetic
      • 2d: Bit Logic
      • 2e: Insecure Hashing
      • 2f: Noun Ordering
      • 2g: Unsigned Powers
      • 2h: Set Logic
      • 2i: Map Logic
      • 2j: Jar and Jug Logic
      • 2k: Queue Logic
      • 2l: Container from Container
      • 2m: Container from Noun
      • 2n: Functional Hacks
      • 2o: Normalizing Containers
      • 2p: Serialization
      • 2q: Molds and Mold-Builders
      • 3a: Modular and Signed Ints
      • 3b: Floating Point
      • 3c: Urbit Time
      • 3d: SHA Hash Family
      • 3e: AES encryption (Removed)
      • 3f: Scrambling
      • 3g: Molds and Mold-Builders
      • 4a: Exotic Bases
      • 4b: Text Processing
      • 4c: Tank Printer
      • 4d: Parsing (Tracing)
      • 4e: Parsing (Combinators)
      • 4f: Parsing (Rule-Builders)
      • 4g: Parsing (Outside Caller)
      • 4h: Parsing (ASCII Glyphs)
      • 4i: Parsing (Useful Idioms)
      • 4j: Parsing (Bases and Base Digits)
      • 4k: Atom Printing
      • 4l: Atom Parsing
      • 4m: Formatting Functions
      • 4n: Virtualization
      • 4o: Molds
      • 5a: Compiler Utilities
      • 5b: Macro Expansion
      • 5c: Compiler Backend & Prettyprinter
      • 5d: Parser
      • 5e: Molds and mold builders
      • 5f: Profiling support
      • Runes

        • Atoms and strings
        • Nock . ('dot')
        • Wild ! ('zap')
        • Change Subject = ('tis')
        • Conditionals ? ('wut')
        • Cores | ('bar')
        • Arms + ('lus')
        • Cells : ('col')
        • Calls % ('cen')
        • Casts ^ ('ket')
        • Structures $ ('buc')
        • Make ; ('mic')
        • Hints ~ ('sig')
        • Imports / ('fas')
        • Terminators -- and ==
        • Limbs and wings

          • Limbs
          • Wings
          • Zuse

            • Table of Contents
            • 2d(1-5): To JSON, Wains
            • 2d(6): From JSON
            • 2d(7): From JSON (unit)
            • 2e(2-3): Print & Parse JSON
          • Arvo

            • Overview
            • Ames

              • Overview
              • Cryptography
              • API Reference
              • Scry Reference
              • Data Types
              • Behn

                • Overview
                • API Reference
                • Scry Reference
                • Examples
                • Clay

                  • Overview
                  • Architecture
                  • Using Clay
                  • Data Types
                  • Scry Reference
                  • API Reference
                  • Examples
                  • Marks

                    • Overview
                    • Writing Marks
                    • Using Marks
                    • Examples
                  • Dill

                    • Overview
                    • API Reference
                    • Scry Reference
                    • Data Types
                    • Eyre

                      • Overview
                      • External API Reference
                      • Internal API Reference
                      • Scry Reference
                      • Data Types
                      • Guide
                      • Gall

                        • Overview
                        • API Reference
                        • Data Types
                        • Threads Reference
                        • Iris

                          • Overview
                          • API Reference
                          • Data Types
                          • Example
                          • Jael

                            • Overview
                            • API Reference
                            • Scry Reference
                            • Data Types
                            • Examples
                            • Threads

                              • Overview
                              • HTTP API
                              • Reference
                              • Gall

                                • Start Thread
                                • Take Result
                                • Take Facts
                                • Stop Thread
                                • Poke Thread
                                • Examples

                                  • Fetch JSON
                                  • Child Thread
                                  • Main-loop
                                  • Poke Agent
                                  • Scry
                                  • Take Fact
                                • Concepts

                                  • Scries
                                  • Subscriptions
                                  • Tutorials

                                    • Move Trace
                                    • Reference

                                      • Cryptography
                                      • Filesystem Hierarchy
                                    • Nock

                                      • Nock Definition
                                      • Explanation
                                      • Example
                                      • Implementations
                                      • Vere

                                        • C Runtime System
                                        • Land of Nouns
                                        • API overview by prefix
                                        • C in Urbit
                                        • Writing Jets
                                        • Cryptography
                                        • Azimuth

                                          • Overview
                                          • Urbit HD Wallet
                                          • Azimuth Data Flow
                                          • Azimuth.eth
                                          • Ecliptic.eth
                                          • Advanced Azimuth Tools
                                          • Life and Rift
                                          • Layer 2

                                            • Layer 2 Overview
                                            • Layer 2 Actions
                                            • Transaction Format
                                            • Rollers
                                            • Roller HTTP RPC-API
                                            • Custom Roller Tutorial
                                          • Glossary

                                            • Ames
                                            • Aqua
                                            • Arm
                                            • Arvo
                                            • Atom
                                            • Azimuth
                                            • Battery
                                            • Behn
                                            • Bridge
                                            • Censures
                                            • chat
                                            • Claims
                                            • Clay
                                            • Comet
                                            • Core
                                            • Delegated Sending
                                            • Desk
                                            • Dill
                                            • Document Proposal
                                            • Dojo
                                            • Door
                                            • Ecliptic
                                            • Event Log
                                            • Eyre
                                            • Galaxy
                                            • Gall
                                            • Gate
                                            • HD Wallet
                                            • Hoon
                                            • Invite Tree
                                            • Iris
                                            • Jael
                                            • Keyfile
                                            • Khan
                                            • Landscape
                                            • Mark
                                            • Moon
                                            • Nock
                                            • Noun
                                            • OTA Updates
                                            • Payload
                                            • pH
                                            • Pier
                                            • Pill
                                            • Planet
                                            • Proxies
                                            • Replay
                                            • Factory Reset
                                            • Naive rollups
                                            • Sail/Udon
                                            • Senate
                                            • Ship
                                            • ship.arvo.network
                                            • Star
                                            • |sync
                                            • Trap
                                            • Upgrade Proposal
                                            • Vane
                                            • Vere
                                            • Voting
                                            • Wallet-Generator
                                            • Additional

                                              • Cryptography
                                              • Software Distribution

                                                • Overview
                                                • Docket File
                                                • Glob
                                              Urbit Developers
                                              • Hoon

                                                • Overview
                                                • Cheat Sheet
                                                • Irregular forms
                                                • Hoon Errors
                                                • Hoon Style Guide
                                                • Basic Types
                                                • Advanced Types
                                                • Auras
                                                • Standard Library

                                                  • 1a: Basic Arithmetic
                                                  • 1b: Tree Addressing
                                                  • 1c: Molds and Mold-Builders
                                                  • 2a: Unit Logic
                                                  • 2b: List Logic
                                                  • 2c: Bit Arithmetic
                                                  • 2d: Bit Logic
                                                  • 2e: Insecure Hashing
                                                  • 2f: Noun Ordering
                                                  • 2g: Unsigned Powers
                                                  • 2h: Set Logic
                                                  • 2i: Map Logic
                                                  • 2j: Jar and Jug Logic
                                                  • 2k: Queue Logic
                                                  • 2l: Container from Container
                                                  • 2m: Container from Noun
                                                  • 2n: Functional Hacks
                                                  • 2o: Normalizing Containers
                                                  • 2p: Serialization
                                                  • 2q: Molds and Mold-Builders
                                                  • 3a: Modular and Signed Ints
                                                  • 3b: Floating Point
                                                  • 3c: Urbit Time
                                                  • 3d: SHA Hash Family
                                                  • 3e: AES encryption (Removed)
                                                  • 3f: Scrambling
                                                  • 3g: Molds and Mold-Builders
                                                  • 4a: Exotic Bases
                                                  • 4b: Text Processing
                                                  • 4c: Tank Printer
                                                  • 4d: Parsing (Tracing)
                                                  • 4e: Parsing (Combinators)
                                                  • 4f: Parsing (Rule-Builders)
                                                  • 4g: Parsing (Outside Caller)
                                                  • 4h: Parsing (ASCII Glyphs)
                                                  • 4i: Parsing (Useful Idioms)
                                                  • 4j: Parsing (Bases and Base Digits)
                                                  • 4k: Atom Printing
                                                  • 4l: Atom Parsing
                                                  • 4m: Formatting Functions
                                                  • 4n: Virtualization
                                                  • 4o: Molds
                                                  • 5a: Compiler Utilities
                                                  • 5b: Macro Expansion
                                                  • 5c: Compiler Backend & Prettyprinter
                                                  • 5d: Parser
                                                  • 5e: Molds and mold builders
                                                  • 5f: Profiling support
                                                  • Runes

                                                    • Atoms and strings
                                                    • Nock . ('dot')
                                                    • Wild ! ('zap')
                                                    • Change Subject = ('tis')
                                                    • Conditionals ? ('wut')
                                                    • Cores | ('bar')
                                                    • Arms + ('lus')
                                                    • Cells : ('col')
                                                    • Calls % ('cen')
                                                    • Casts ^ ('ket')
                                                    • Structures $ ('buc')
                                                    • Make ; ('mic')
                                                    • Hints ~ ('sig')
                                                    • Imports / ('fas')
                                                    • Terminators -- and ==
                                                    • Limbs and wings

                                                      • Limbs
                                                      • Wings
                                                      • Zuse

                                                        • Table of Contents
                                                        • 2d(1-5): To JSON, Wains
                                                        • 2d(6): From JSON
                                                        • 2d(7): From JSON (unit)
                                                        • 2e(2-3): Print & Parse JSON
                                                      • Arvo

                                                        • Overview
                                                        • Ames

                                                          • Overview
                                                          • Cryptography
                                                          • API Reference
                                                          • Scry Reference
                                                          • Data Types
                                                          • Behn

                                                            • Overview
                                                            • API Reference
                                                            • Scry Reference
                                                            • Examples
                                                            • Clay

                                                              • Overview
                                                              • Architecture
                                                              • Using Clay
                                                              • Data Types
                                                              • Scry Reference
                                                              • API Reference
                                                              • Examples
                                                              • Marks

                                                                • Overview
                                                                • Writing Marks
                                                                • Using Marks
                                                                • Examples
                                                              • Dill

                                                                • Overview
                                                                • API Reference
                                                                • Scry Reference
                                                                • Data Types
                                                                • Eyre

                                                                  • Overview
                                                                  • External API Reference
                                                                  • Internal API Reference
                                                                  • Scry Reference
                                                                  • Data Types
                                                                  • Guide
                                                                  • Gall

                                                                    • Overview
                                                                    • API Reference
                                                                    • Data Types
                                                                    • Threads Reference
                                                                    • Iris

                                                                      • Overview
                                                                      • API Reference
                                                                      • Data Types
                                                                      • Example
                                                                      • Jael

                                                                        • Overview
                                                                        • API Reference
                                                                        • Scry Reference
                                                                        • Data Types
                                                                        • Examples
                                                                        • Threads

                                                                          • Overview
                                                                          • HTTP API
                                                                          • Reference
                                                                          • Gall

                                                                            • Start Thread
                                                                            • Take Result
                                                                            • Take Facts
                                                                            • Stop Thread
                                                                            • Poke Thread
                                                                            • Examples

                                                                              • Fetch JSON
                                                                              • Child Thread
                                                                              • Main-loop
                                                                              • Poke Agent
                                                                              • Scry
                                                                              • Take Fact
                                                                            • Concepts

                                                                              • Scries
                                                                              • Subscriptions
                                                                              • Tutorials

                                                                                • Move Trace
                                                                                • Reference

                                                                                  • Cryptography
                                                                                  • Filesystem Hierarchy
                                                                                • Nock

                                                                                  • Nock Definition
                                                                                  • Explanation
                                                                                  • Example
                                                                                  • Implementations
                                                                                  • Vere

                                                                                    • C Runtime System
                                                                                    • Land of Nouns
                                                                                    • API overview by prefix
                                                                                    • C in Urbit
                                                                                    • Writing Jets
                                                                                    • Cryptography
                                                                                    • Azimuth

                                                                                      • Overview
                                                                                      • Urbit HD Wallet
                                                                                      • Azimuth Data Flow
                                                                                      • Azimuth.eth
                                                                                      • Ecliptic.eth
                                                                                      • Advanced Azimuth Tools
                                                                                      • Life and Rift
                                                                                      • Layer 2

                                                                                        • Layer 2 Overview
                                                                                        • Layer 2 Actions
                                                                                        • Transaction Format
                                                                                        • Rollers
                                                                                        • Roller HTTP RPC-API
                                                                                        • Custom Roller Tutorial
                                                                                      • Glossary

                                                                                        • Ames
                                                                                        • Aqua
                                                                                        • Arm
                                                                                        • Arvo
                                                                                        • Atom
                                                                                        • Azimuth
                                                                                        • Battery
                                                                                        • Behn
                                                                                        • Bridge
                                                                                        • Censures
                                                                                        • chat
                                                                                        • Claims
                                                                                        • Clay
                                                                                        • Comet
                                                                                        • Core
                                                                                        • Delegated Sending
                                                                                        • Desk
                                                                                        • Dill
                                                                                        • Document Proposal
                                                                                        • Dojo
                                                                                        • Door
                                                                                        • Ecliptic
                                                                                        • Event Log
                                                                                        • Eyre
                                                                                        • Galaxy
                                                                                        • Gall
                                                                                        • Gate
                                                                                        • HD Wallet
                                                                                        • Hoon
                                                                                        • Invite Tree
                                                                                        • Iris
                                                                                        • Jael
                                                                                        • Keyfile
                                                                                        • Khan
                                                                                        • Landscape
                                                                                        • Mark
                                                                                        • Moon
                                                                                        • Nock
                                                                                        • Noun
                                                                                        • OTA Updates
                                                                                        • Payload
                                                                                        • pH
                                                                                        • Pier
                                                                                        • Pill
                                                                                        • Planet
                                                                                        • Proxies
                                                                                        • Replay
                                                                                        • Factory Reset
                                                                                        • Naive rollups
                                                                                        • Sail/Udon
                                                                                        • Senate
                                                                                        • Ship
                                                                                        • ship.arvo.network
                                                                                        • Star
                                                                                        • |sync
                                                                                        • Trap
                                                                                        • Upgrade Proposal
                                                                                        • Vane
                                                                                        • Vere
                                                                                        • Voting
                                                                                        • Wallet-Generator
                                                                                        • Additional

                                                                                          • Cryptography
                                                                                          • Software Distribution

                                                                                            • Overview
                                                                                            • Docket File
                                                                                            • Glob
                                                                                          Reference/Hoon/Standard Library

                                                                                          2p: Serialization

                                                                                          ++cue

                                                                                          Unpack atom to noun

                                                                                          Produces a noun unpacked from atom a. The inverse of +jam.

                                                                                          Accepts

                                                                                          a is an atom.

                                                                                          Produces

                                                                                          A noun.

                                                                                          Source

                                                                                          ++ cue
                                                                                          ~/ %cue
                                                                                          |= a=@
                                                                                          ^- *
                                                                                          =+ b=0
                                                                                          =+ m=`(map @ *)`~
                                                                                          =< q
                                                                                          |- ^- [p=@ q=* r=(map @ *)]
                                                                                          ?: =(0 (cut 0 [b 1] a))
                                                                                          =+ c=(rub +(b) a)
                                                                                          [+(p.c) q.c (~(put by m) b q.c)]
                                                                                          =+ c=(add 2 b)
                                                                                          ?: =(0 (cut 0 [+(b) 1] a))
                                                                                          =+ u=$(b c)
                                                                                          =+ v=$(b (add p.u c), m r.u)
                                                                                          =+ w=[q.u q.v]
                                                                                          [(add 2 (add p.u p.v)) w (~(put by r.v) b w)]
                                                                                          =+ d=(rub c a)
                                                                                          [(add 2 p.d) (need (~(get by m) q.d)) m]

                                                                                          Examples

                                                                                          > (jam [1 2 3])
                                                                                          3.426.417
                                                                                          > (cue 3.426.417)
                                                                                          [1 2 3]

                                                                                          ++jam

                                                                                          Pack noun to atom

                                                                                          Produces an atom packed from noun a. The inverse of +cue.

                                                                                          Accepts

                                                                                          a is a noun.

                                                                                          Produces

                                                                                          An atom.

                                                                                          Source

                                                                                          ++ jam
                                                                                          ~/ %jam
                                                                                          |= a=*
                                                                                          ^- @
                                                                                          =+ b=0
                                                                                          =+ m=`(map * @)`~
                                                                                          =< q
                                                                                          |- ^- [p=@ q=@ r=(map * @)]
                                                                                          =+ c=(~(get by m) a)
                                                                                          ?~ c
                                                                                          => .(m (~(put by m) a b))
                                                                                          ?: ?=(@ a)
                                                                                          =+ d=(mat a)
                                                                                          [(add 1 p.d) (lsh 0 q.d) m]
                                                                                          => .(b (add 2 b))
                                                                                          =+ d=$(a -.a)
                                                                                          =+ e=$(a +.a, b (add b p.d), m r.d)
                                                                                          [(add 2 (add p.d p.e)) (mix 1 (lsh [0 2] (cat 0 q.d q.e))) r.e]
                                                                                          ?: ?&(?=(@ a) (lte (met 0 a) (met 0 u.c)))
                                                                                          =+ d=(mat a)
                                                                                          [(add 1 p.d) (lsh 0 q.d) m]
                                                                                          =+ d=(mat u.c)
                                                                                          [(add 2 p.d) (mix 3 (lsh [0 2] q.d)) m]

                                                                                          Examples

                                                                                          > (jam 1)
                                                                                          12
                                                                                          > (cue 12)
                                                                                          1
                                                                                          > (jam [1 1])
                                                                                          817
                                                                                          > (cue 817)
                                                                                          [1 1]
                                                                                          > (jam [~ u=19])
                                                                                          39.689
                                                                                          > (cue 39.689)
                                                                                          [0 19]

                                                                                          ++mat

                                                                                          Length-encode

                                                                                          Produces a cell whose tail q is atom a with a bit representation of its length prepended to it (as the least significant bits). The head p is the length of q in bits.

                                                                                          Accepts

                                                                                          a is an atom.

                                                                                          Produces

                                                                                          A cell of two atoms, p and q.

                                                                                          Source

                                                                                          ++ mat
                                                                                          ~/ %mat
                                                                                          |= a=@
                                                                                          ^- [p=@ q=@]
                                                                                          ?: =(0 a)
                                                                                          [1 1]
                                                                                          =+ b=(met 0 a)
                                                                                          =+ c=(met 0 b)
                                                                                          :- (add (add c c) b)
                                                                                          (cat 0 (bex c) (mix (end [0 (dec c)] b) (lsh [0 (dec c)] a)))

                                                                                          Examples

                                                                                          > (mat 0xaaa)
                                                                                          [p=20 q=699.024]
                                                                                          > (met 0 q:(mat 0xaaa))
                                                                                          20
                                                                                          > `@ub`q:(mat 0xaaa)
                                                                                          0b1010.1010.1010.1001.0000
                                                                                          > =a =-(~&(- -) `@ub`0xaaa)
                                                                                          0b1010.1010.1010
                                                                                          > =b =-(~&(- -) `@ub`(xeb a))
                                                                                          0b1100
                                                                                          > =b =-(~&(- -) `@ub`(met 0 a))
                                                                                          0b1100
                                                                                          > =c =-(~&(- -) (xeb b))
                                                                                          4
                                                                                          > [`@ub`a `@ub`(end 0 (dec c) b) `@ub`(bex c)]
                                                                                          [0b1010.1010.1010 0b100 0b1.0000]

                                                                                          Discussion

                                                                                          mat is only used internally as a helper to jam.


                                                                                          ++rub

                                                                                          Length-decode

                                                                                          The inverse of mat. Accepts a cell of index a and a bitstring b and produces the cell whose tail q is the decoded atom at index a and whose head is the length of the encoded atom q, by which the offset a is advanced.

                                                                                          Accepts

                                                                                          a is an atom.

                                                                                          b is a bitstring as an atom.

                                                                                          Produces

                                                                                          A cell of two atoms, p and q.

                                                                                          Source

                                                                                          ++ rub
                                                                                          ~/ %rub
                                                                                          |= [a=@ b=@]
                                                                                          ^- [p=@ q=@]
                                                                                          =+ ^= c
                                                                                          =+ [c=0 m=(met 0 b)]
                                                                                          |- ?< (gth c m)
                                                                                          ?. =(0 (cut 0 [(add a c) 1] b))
                                                                                          c
                                                                                          $(c +(c))
                                                                                          ?: =(0 c)
                                                                                          [1 0]
                                                                                          =+ d=(add a +(c))
                                                                                          =+ e=(add (bex (dec c)) (cut 0 [d (dec c)] b))
                                                                                          [(add (add c c) e) (cut 0 [(add d (dec c)) e] b)]

                                                                                          Examples

                                                                                          > `@ub`(jam 0xaaa)
                                                                                          0b1.0101.0101.0101.0010.0000
                                                                                          > (rub 1 0b1.0101.0101.0101.0010.0000)
                                                                                          [p=20 q=2.730]
                                                                                          > `@ux`q:(rub 1 0b1.0101.0101.0101.0010.0000)
                                                                                          0xaaa

                                                                                          Discussion

                                                                                          rub is only used internally as a helper to cue.


                                                                                          <-

                                                                                          2o: Normalizing Containers

                                                                                          2q: Molds and Mold-Builders

                                                                                          ->

                                                                                          Edit this page on GitHub