Day 1

gate == function

0 == zod

|=
  n=@ud
  %-
    ....things

|= is a gate, accepts two arguments. name/face, attached to a type (n=@ud) and a sen hep %-, function call. invoking a function

| - function or loop-like. something you can re-enter. = definitions ^ type things ? test things

|- invokes a functoin %= recalculates something that’s in your current tree.

spaces do something. gaps separate rune children

Hoon is a subject-oriented programming language. you can only see certain things above and around you. similar to variable scope, but different.


Auras

everything is an unsigned decimal. to make something look different, you need to attach some metadata.

backticks: “apply it to the number following”


anything that starts with a dot is a 32-bit single-precision, floating-point number. like .0.5

add:rs in order to add floating-point numbers. when you work with a particular aura, you need to use the specific operator for it.

> (add:rs .0.5 5)
-need.@rs
-have.@ud
nest-fail
dojo: hoon expression failed

need/have means you’re running into an issue with types.

good practice to cast types in hoon so that you can get failures close to where the problem is.

^+ type cast as example. ^- type cast explicitly.

~ anything starting with a sig is a hint, tells the runtime to do something else. this is how hoon accomplishes side-effects. ~_ some kind of error-tracing tool.

~/ hint to jets. so on add ~/ %add , if there is a jet called ‘add’, use it - otherwise run as usual below.

++ add - a label. inside a core (in this case, inside the rs core.)


  • iterate from 1 and 1000,
  • on each, if mod 3 === 0 || mod 5 === 0, multiply
> =fib |=  n=@ud
  %-  flop
  =+  [i=0 p=0 q=1 r=*(list @ud)]
  |-  ^+  r
  ?:  =(i n)  r
  %=  $
  i  +(i)
  p  q
  q  (add p q)
  r  [q r]
  ==

* empty value of a given type

|=  n=@ud               ;; take a single value as unsigned decimal.
;; we want to generate a list.
=+  [i=0 r=*(list @ud)] ;; variables we need
|-  ^-  (list @ud)      ;; recursion point trap. for a loop
?:  =(i n)  r           ;; check for exit/completion
?:  =((mod i 3) 0)      ;; when divisible by three...
  %=  $
    i  +(i)             ;; increment i by one...
    r  [i r]            ;; and then add it to the list
  ==
?:  =((mod i 5) 0)      ;; when divisible by five...
  %=  $
    i  +(i)
    r  [i r]
  ==
%=  $                   ;; false branch:
  i  +(i)               ;; increment i
  r  r                  ;; no change in r
==

$ is the default thing that isn’t named inside a “subject” (?).

roll like a fold operation. takes two children, first child is list, second child is what to do to the items there.

:_ reverse the order of two children. can be used for developer purposes to put blocks above or below each other, organizationally.

@ - atom

'single quotes' - single value atom, string. "double quores" - double quotes == array/list

casting through an emtpy aura “clears the metadata”:

`(list @ud)``(list @)`"Urbit"

~ in front of the list is a convention (as in ~[10 20 22]- it’s the \0 null character at the end of the list

Cores

code and data.

battery has arms. this is the code.

the one arm in |= is called $.

Door = core with a sample.

++ is an arm label.

Links to this page