Urbit Developers
  • Hoon

    • Overview
    • Cheat Sheet
    • Irregular forms
    • Hoon Errors
    • Hoon Style Guide
    • Basic Types
    • Advanced Types
    • Auras
    • 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
        • Standard library

          • Table of Contents
          • 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
          • 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
                              • Basics

                                • Fundamentals
                                • Bind
                                • Input
                                • Output
                                • Summary
                                • 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
                                                Urbit
                                                • Hoon

                                                  • Overview
                                                  • Cheat Sheet
                                                  • Irregular forms
                                                  • Hoon Errors
                                                  • Hoon Style Guide
                                                  • Basic Types
                                                  • Advanced Types
                                                  • Auras
                                                  • 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
                                                      • Standard library

                                                        • Table of Contents
                                                        • 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
                                                        • 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
                                                                            • Basics

                                                                              • Fundamentals
                                                                              • Bind
                                                                              • Input
                                                                              • Output
                                                                              • Summary
                                                                              • 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
                                                                                              Reference/Arvo/Threads/Basics

                                                                                              Bind

                                                                                              Having looked at form and pure, we'll now look at the last strand arm bind. Bind is typically used in combination with micgal (;<).

                                                                                              Micgal

                                                                                              Micgal takes four arguments like spec hoon hoon hoon. Given ;< a b c d, it composes them like ((b ,a) c |=(a d)). So, for example, these two expressions are equivalent:

                                                                                              ;< ~ bind:m (sleep:strandio ~s2)
                                                                                              (pure:m !>(~))

                                                                                              and

                                                                                              ((bind:m ,~) (sleep:strandio ~s2) |=(~ (pure:m !>(~))))

                                                                                              Micgal exists simply for readability. The above isn't too bad, but consider this:

                                                                                              ;< a b c
                                                                                              ;< d e f
                                                                                              ;< g h i
                                                                                              j

                                                                                              ...as opposed to this monstrosity: ((b ,a) c |=(a ((e ,d) f |=(d ((h ,g) i |=(g j))))))

                                                                                              bind

                                                                                              Bind by itself must be specialised like (bind:m ,<type>) and it takes two arguments:

                                                                                              • The first argument is a function that returns the form of a strand which produces <type>.
                                                                                              • The second argument is a gate whose sample is <type> and which returns a form.

                                                                                              Since you'll invariably use it in conjunction with micgal, the <type> in ;< <type> bind:m ... will both specialise bind and specify the gate's sample.

                                                                                              Bind calls the first function then, if it succeeded, calls the second gate with the result of the first as its sample. If the first function failed, it will instead just return an error message and not bother calling the next gate. So it's essentially "strand A then strand B".

                                                                                              Since the second gate may itself contain another ;< <type> bind:m ..., you can see how this allows you to glue together an arbitrarily large pipeline, where subsequent gates depend on the previous ones.

                                                                                              strandio

                                                                                              /lib/strandio/hoon contains a large collection of useful, ready-made functions for use in threads. For example:

                                                                                              • sleep waits for the specified time.
                                                                                              • get-time gets the current time.
                                                                                              • poke pokes an agent.
                                                                                              • watch subscribes to an agent.
                                                                                              • fetch-json produces the JSON at a particular URL.
                                                                                              • retry tries a strand repeatedly with exponential backoff until it succeeds.
                                                                                              • start-thread starts another thread.
                                                                                              • send-raw-card sends any card.

                                                                                              ...and many more.

                                                                                              Putting it together

                                                                                              Here's a simple thread with a couple of strandio functions:

                                                                                              /- spider
                                                                                              /+ strandio
                                                                                              =, strand=strand:spider
                                                                                              ^- thread:spider
                                                                                              |= arg=vase
                                                                                              =/ m (strand ,vase)
                                                                                              ^- form:m
                                                                                              ;< t=@da bind:m get-time:strandio
                                                                                              ;< s=ship bind:m get-our:strandio
                                                                                              (pure:m !>([s t]))

                                                                                              Save it as /ted/mythread.hoon of %base, |commit it and run it with -mythread. You should see something like:

                                                                                              > -mythread
                                                                                              [~zod ~2021.3.8..14.52.15..bdfe]

                                                                                              Analysis

                                                                                              To use strandio functions we've imported the library with /+ strandio.

                                                                                              get-time and get-our get the current time & ship from the bowl in strand-input. We'll discuss strand-input in more detail later.

                                                                                              Note how we've specified the face and return type of each strand like [email protected], etc.

                                                                                              You can see how pure has access to the results of previous strands in the pipeline. Note how we've wrapped pure's argument in a !> because the thread must produce a vase.

                                                                                              Next we'll look at strand-input in more detail.

                                                                                              <-

                                                                                              Fundamentals

                                                                                              Input

                                                                                              ->

                                                                                              Edit this page on GitHub