: col · Cells
The : ("col") expressions are used to produce cells, which are pairs of values. E.g., :-(p q) produces the cell [p q]. All : runes reduce to :-.
:- "colhep"
Construct a cell (2-tuple).
Syntax
Two arguments, fixed.
:- p
q:-(p q)[p q]p^qAST
[%clhp p=hoon q=hoon]Produces
The cell of .p and .q.
Discussion
Hoon expressions actually use the same "autocons" pattern as Nock formulas. If you're assembling expressions (which usually only the compiler does), [a b] is the same as :-(a b).
Examples
> :-(1 2)
[1 2]
~zod:dojo> 1^2
[1 2]:_ "colcab"
Construct a cell, inverted.
Syntax
Two arguments, fixed.
:_ p
q:_(p q)None
AST
[%clcb p=hoon q=hoon]Expands to
:-(q p)Examples
> :_(1 2)
[2 1]:+ "collus"
Construct a triple (3-tuple).
Syntax
Three arguments, fixed.
:+ p
q
r:+(p q r) [p q r]AST
[%clls p=hoon q=hoon r=hoon]Expands to:
:-(p :-(q r))Examples
> :+ 1
2
3
[1 2 3]
> :+(%a ~ 'b')
[%a ~ 'b']:^ "colket"
Construct a quadruple (4-tuple).
Syntax
Four arguments, fixed.
:^ p
q
r
s:^(p q r s) [p q r s]AST
[%clkt p=hoon q=hoon r=hoon s=hoon]Expands to
:-(p :-(q :-(r s)))Examples
> :^(1 2 3 4)
[1 2 3 4]
> :^ 5
6
7
8
[5 6 7 8]:* "coltar"
Construct an n-tuple.
Syntax
Variable number of arguments.
:* p1
p2
p3
pn
==:*(p1 p2 p3 pn)[p1 p2 p3 pn]AST
[%cltr p=(list hoon)]Expands to
Pseudocode: a, b, c, ... as elements of .p:
:-(a :-(b :-(c :-(... z)))))Desugaring
|-
?~ p
!!
?~ t.p
i.p
:- i.p
$(p t.p)Examples
> :*(5 3 4 1 4 9 0 ~ 'a')
[5 3 4 1 4 9 0 ~ 'a']
> [5 3 4 1 4 9 0 ~ 'a']
[5 3 4 1 4 9 0 ~ 'a']
> :* 5
3
4
1
4
9
0
~
'a'
==
[5 3 4 1 4 9 0 ~ 'a']:~ "colsig"
Construct a null-terminated list.
Syntax
Variable number of arguments.
:~ p1
p2
p3
pn
==:~(p1 p2 p3 pn)~[p1 p2 p3 pn]AST
[%clsg p=(list hoon)]Expands to
Pseudocode: a, b, c, ... as elements of .p:
:-(a :-(b :-(c :-(... :-(z ~)))))Desugaring
|-
?~ p
~
:- i.p
$(p t.p)Discussion
Note that this does not produce a +list type, it just produces a null-terminated n-tuple. To make it a proper +list it must be cast or molded.
Examples
> :~(5 3 4 2 1)
[5 3 4 2 1 ~]
> ~[5 3 4 2 1]
[5 3 4 2 1 ~]
> :~ 5
3
4
2
1
==
[5 3 4 2 1 ~]:: "colcol"
Code comment.
Syntax
:: any text you like!Examples
::
:: this is commented code
::
|= a=@ :: a gate
(add 2 a) :: that adds 2
:: to the inputLast updated