Hoon's Simplified Expression- Analysis
What Is Hoon's Simplified Expression-Analysis
Hoon's Simplified Expression-Analysis is a practical approach to understanding how the Hoon programming language parses and evaluates code. If you're learning Hoon and the standard documentation feels overwhelming, this method cuts through the noise.
Hoon is Urbit's native language. It's a functional, statically typed language that looks strange if you're used to JavaScript or Python. The syntax uses runes instead of keywords. That's the first thing that trips most people up.
Most tutorials try to explain Hoon's theory first. This creates a problem. You're reading abstract concepts without seeing how they actually work in code. Simplified Expression-Analysis flips that. You look at expressions, break them down, and learn the theory as you go.
The Core Problem with Learning Hoon
Hoon has a steep learning curve. Not because it's poorly designed, but because it doesn't look like anything else you've used. Traditional programming languages use words like if, else, for. Hoon uses symbols like ?:, |-, %=.
The documentation assumes you're comfortable with functional programming concepts. It throws around terms like tail position, wing resolution, and noun anatomy without easing you in. If you're new to this, you'll spend hours trying to understand a single page.
Simplified Expression-Analysis ignores the jargon. You start with the simplest possible unit: an expression. You learn what it does by examining it directly, not by reading definitions.
How Expression-Analysis Works
Every piece of Hoon code is a noun. A noun is either an atom (a number) or a cell (a pair of nouns). That's it. Everything else in Hoon builds from this foundation.
When you analyze an expression, you ask three questions:
- What rune is being used?
- What are the sub-expressions doing?
- What is the final result?
You don't need to understand the type system first. You don't need to know about the subject. You just need to look at the code and trace what happens.
Breaking Down a Simple Expression
Consider this Hoon code:
%+ add 2 3
Using Simplified Expression-Analysis:
- The rune is
%+, which calls a function with two arguments - The function is
add - The arguments are
2and3 - The result is
5
You don't need to know that %+ is a cencol rune or that it operates in the wing of the subject. The breakdown tells you everything you need to use it.
Rune Categories You Actually Need
Hoon has over 100 runes. You don't need all of them to start. Simplified Expression-Analysis focuses on the ones you'll encounter constantly.
| Rune | Purpose | Frequency |
|---|---|---|
?: |
Conditional (if/else) | Very high |
%= |
Recursion/call | High |
|+ |
Create a function | High |
^- |
Type cast | Medium |
|= |
Create a gate (named function) | High |
%+ |
Call with two arguments | High |
$> |
Type promotion | Medium |
Learn these first. Everything else is variations or edge cases you'll pick up naturally.
Common Patterns Without the Theory
The "Hello World" Equivalent
|% ++ name "Hello, World!"
--
This creates a core (a library of functions). The function name simply returns the string. That's all you need to know right now.
Making a Decision
?:(=(x 10) "yes" "no")
If x equals 10, you get "yes". Otherwise, you get "no". The ?: rune is Hoon's if-then-else. The = rune checks equality.
Looping (Recursion, Actually)
|- ?: (lte i 10)
(add i $(i (add i 1)))
0
This adds all numbers from 1 to 10. The |- rune creates a base case. The $() syntax recurses with modified arguments. Yes, Hoon uses recursion for loops. Get used to it.
Getting Started: Your First Analysis Session
You need Urbit running to test Hoon code. If you don't have it set up, that's your first step.
- Install Urbit from urbit.org
- Start a fake ship:
./urbit -F zod - Open the Dojo (Urbit's shell) in your terminal or browser
Once you're in the Dojo, type:
+hello
If the hello generator exists, you'll see output. To write your own code, use the |new-file generator or edit files in the /gen desk.
A Simple Exercise
Write a function that takes two numbers and returns their product. Use Simplified Expression-Analysis to verify it works.
|= [a=@ud b=@ud]
(mul a b)
Break it down:
|=creates a gate (function)[a=@ud b=@ud]defines two unsigned decimal inputs(mul a b)multiplies them using themularm from the standard library
Test it in Dojo:
+mul [5 7]
You should see 35.
Where People Get Stuck
The most common mistake is trying to understand everything before writing anything. You don't need to master type theory to write a working function. You need to understand what your code does, step by step.
Another issue is rune memorization. Don't memorize. Recognize. When you see ?:, your brain should immediately think "conditional." When you see |=, think "function." This comes from practice, not flashcards.
The third problem is fighting the syntax. Hoon looks weird. It will always look weird. Stop trying to make it look like other languages. Embrace the runes. They're more consistent than English keywords anyway.
What Simplified Expression-Analysis Is Not
This is not a replacement for the Hoon documentation. The docs are comprehensive and accurate. They're just not accessible to beginners.
This is not a way to avoid learning Hoon's type system. Types matter in Hoon. Eventually, you'll need to understand faces, marks, and structures. But you can write useful code before that click happens.
This is not about writing Hoon "the easy way." There is no easy way. Hoon requires effort. Simplified Expression-Analysis just removes unnecessary friction from the learning process.
The Bottom Line
If you want to learn Hoon, stop reading tutorials that start with "Hoon is a functional programming language..." Start with code. Analyze it. Break it into pieces. See what happens when you change things.
Simplified Expression-Analysis is just a fancy name for what should be obvious: look at the code, understand what it does, build from there. The fancy name exists because people needed a reason to stop reading and start doing.
So stop reading. Open your Dojo. Write something.