@@ -0,0 +1,79 @@
7+Write a door that can act as a bank account with the ability to withdraw, deposit, and check the balance.
24+ +>.$(balance (add balance amount))
27+ +>.$(balance (sub balance amount))
32+We start with the three lines we have in every `%say` generator.
40+We're creating a cell the head of which is a `%say` and the tail of which is a gate that produces a cell with a head of the mark of the kind of data we are going to produce.
51+Here we're going to compose two runes using `=<` which has inverted arguments. We use this rune to keep the heaviest twig to the bottom of the code.
53+`=~` is a rune that composes multiple expressions. We take `new-account` and use that as the subject for the call to `deposit`. `deposit` and `withdraw` both produce a new version of the door which is used in subsequent calls which is why we are able to chain them in this fashion, the final reference is to `balance` which is the balance contain in the core we are about to examine.
61+ +>.$(balance (add balance amount))
64+ +>.$(balance (sub balance amount))
69+We've chosen here to wrap our door in it's own core to emulate the style of programming that is used when creating libraries. `new-account` is the name of our door. Recall that a door is a core with one or more arms that has a sample. Here our door has a sample of one `@ud` with the face `balance` and two arms, `deposit` and `withdraw`.
71+Each of these arms produces a gate which takes an `@ud` argument. Each of these gates has a similar bit of code inside.
74++>.$(balance (add balance amount))
77+With wing syntax remember that we're looking for `+>`, or the 3rd element, out of `$`, which is to say the subject of the gate we are in, which is the entire `new-account` door. We change `balance` to be the result of adding `balance` and `amount` and produce the door as the result. `withdraw` functions the same way only doing subtraction instead of addition.
79+The important point to notice here is that the sample, `balance`, is stored as part of the door rather than existing outside of it.