Learn me a Hoon

> +list

The + tells Dojo it’s looking for a generator named list.

Runes

|= is a rune. Runes are a pair of symbols, and they function like keywords do in other languages. They (and all Hoon expresssions) are separated from each other by two spaces / gap.

Runes take fixed number of children (which can themselves be runes with children). Hoons works by running through these until a value - not a rune - is arrived at.

|= Gates “bar tis”

Gates

|= forms a gate. A gate is like a function. Takes an input, performs computation, produces output.

|= end=@ [....other stuff...] creates a gate.

  • Children: 2
    • first: input name and type
    • second: computation / how to produce output

The first child of this rune gate is the input - it’s name and type. The input is being named “end” and is type @ or atom or natural number.

The second child is how the gate produces output.

Every gate has a $ arm, which is the compuation arm. Calling $ within the gate is the way to perform recursion (by calling its own computation).

=/ Store value / face “tis fas”

Create a face.

=/ count=@ 1.

  • Children: 3
    • first: name and type
    • second: the value
    • third: #TODO

|- Recursion restart point “bar hep”

  • Children: 1
    • The recursive process? #TODO

^- Output type constraint “ket hep”

^- (list @)

  • Children: 2
    • first: what kind of output the gate creates
    • second: #TODO

? Wut family

?: Evaluate boolean “wut col”

Determines whether its first child is true or false.
If true, branch to second child. If false, branch to third

  • Children: 3
    • first: expression to evaluate
    • second: branch for true
    • third: branch fo false

?& logical AND “wut pam”

All true?

  • Children: inifite
    • end arguments with ==

?| logical OR “wut bar”

Any true?

  • Children: infinite
    • end arguments with ==

?! logical NOT “wut zap”

Inverts truth value of single child

  • Chidren: 1

?.... “wut …”

  • ?~ branch on whether a wing is null. 3
  • ?- #TODO

.= Check equality “dottis”

Regular form: .= child1 child2 Irregular form: =(child1 child2)

Determine if children are equivalent

  • Children: 2
    • first: thing to check
    • second: the other thing to check

~ Null value “sig”

Lists in Hoon end with a sig.

:- Create cell “colhep”

:- firstThing secondThing == [firstThing secondThing]

  • Chidren: 2
    • first: first item in the cell
    • second: second item in the cell

Expressions

`` Cast

Types

  • @ Atom - a natural number. (technically a trivial tree of a single leaf)
  • '' Cord @t - Strings encoded as atoms. insids single quotes 'Hello world'
  • % Term @tas - Constants, for tagging data in the type system. Must be lowercase letters, numbers, hyphens. Kebab-case.

Tall and Wide

Tall uses gaps and/or linebreaks:

	:-  1  2
	
	:: OR
	
	:- 1
	2
	
	:: OR
	
	:-
	1
	2

Wide uses aces and pals/pars and cannot have gaps

:-(1 2) ::only this

Prefer the wide form when writing an expression on a single line.

Irregular expressions

Some rune expressions have an irregular (wide) form.

For instance, .= (test for equality) is normally:

.=(22 11)

and its irregular form is =() like so:

=(22 11)

Gate-calling (for two arguments) is done with %+ (cenlus), as in calling the add gate with a two-argument sample of 2 2:

%+ add 2 2 or %+(add 2 2)

And but its irregular form is just ():

(add 2 2)

The same applies for %-, which is for calling a gate with a single argument:

%- dec 4 or irregularly: (dec 4)

Data Structures

Noun

Either an atom or a cell.

Cell

[1 2]

An ordered pair of two values. [Head Tail]

When displaying in the dojo, the rightmost nouns are considered to be the tail cells. Or: the tail of the whole cell is considered to be a cell of the rightmost nouns.

List

Cast to list of nouns: (list @)[1 2 3 4 5 ~]

Terminate with ~

A Non-null list is called a lest (and is not the same type as a list.)

List standard library functions

Cord / string '' @t

'This is a cord'

> `(list @)'This is a cord'`
  2.037.307.443.564.446.887.986.503.990.470.772

Can also cast with the word ‘cord’:

`cord`'this is a cord'

Tape / string "" @tD tape (cast)

"This is a tape"

Actually a list of ASCII characters (compare to above):

> `(list @)`"this is a tape"
  ~[116 104 105 115 32 105 115 32 97 32 116 97 112 101]

Can also cast with the word ‘tape’:

`tape`"this is a tape"

Auras

Metadata used to determine how to interpret an atom. “What kind of information is this atom?”.

list-of-hoon-auras

#TODO