Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :: Hoon 101: Assignment 3a. Comment each line of code to tell the reader what the code is doing.
- :: Comments should be written as "breathing comments" as suggested in the Hoon Style Guide: https://urbit.org/docs/learn/hoon/style/
- |= n=@ud
- :: This is a gate that assigns the face n to an unsigned decimal
- ::
- =/ t=@ud 1
- :: This assigns a face to an unsigned decimal (ud) and sets its initial value to 1
- ::
- |-
- :: This creates a new one $ armed gate and call the gate
- ::
- ?: =(n 1)
- :: This is a boolean which branches on whether n is equal to 1
- ::
- t
- ::If n is equal to one, we print t.
- ::
- $(n (dec n), t (mul t n))
- ::If n is not equal to one, the recursion starts. We start by multiplying n by t, which produces a new value for t. We then decrement n by 1, and multiply this new n by our new t, which gives us an even newer t. We decrement our new n to find a newer n, and mulitply this by our even newer t. This goes on until n=1 and, will return n!.
- ::
- Assignment 3b
- :: This doesn't work, but I just got called in to emergency bar tend, and this is what I am currently tinkering with:
- |= b=(list @)
- =/ a=@ud 3
- ?: =(a 0) i.b
- $(a (dec a), b t.b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement