To get anything done in Smojo, you need to use its stack. There are a few built-in words you can use:
Pops the top item off the stack and discards it. This item is lost and can't be retrieved.
Duplicates the top of the stack. For example,
1 DUPends up with
1 1on the stack. Note that
DUPdoes not re-create things on the stack; it merely duplicates pointers to things.
Swaps the top two items on the stack. For example,
"Hello" "World" SWAPends up with
"World" "Hello"on the stack.
Question 1Write a word called
DOUBLEthat puts double the number on the top of the stack. For example,
23 double .should display 46
: double dup +. ;
Question 2Write a word called
1/that puts reciprocal of the number on the top of the stack. For example,
5 1/ .should display 0.2
: 1/ 1 swap /. ;