a small calculator written in Io.
Go to file
trans_soup 0a3ba31c22 refactor main program to use quote blocks. 2023-11-01 14:54:01 +01:00
examples add square example. 2023-10-31 18:12:15 +01:00
README.md add square example. 2023-10-31 18:12:15 +01:00
church-bools.txt add church bools demo program. 2023-10-31 17:44:16 +01:00
cons_demo.txt separate cons cell demo from `program.txt`. 2023-11-01 14:30:09 +01:00
functions.io add `read_word` function. 2023-11-01 14:24:43 +01:00
main.io refactor `doall` method. 2023-11-01 14:20:36 +01:00
operators.io add equality checking operation `=`. 2023-11-01 14:27:55 +01:00
program.txt refactor main program to use quote blocks. 2023-11-01 14:54:01 +01:00

README.md

Io calculator

what?

a small, stack-based calculator/programming language inspired by forth.

why?

i wanted to learn a little bit about the Io language. also, i wanted to practice programming in general.

how?

install the Io interpreter from the linked site. then, run io main.io. if you want to check out one of the demo programs, say for instance program.txt, run io main.io program.txt instead.

running the program will put you into a REPL. you can enter words (whitespace-separated strings) here, and they will be executed in order. here are some of the things you can do:

word meaning
any number push the number onto the stack.
+ pop a, then b, then push a+b.
- pop a, then b, then push b-a.
* pop a, then b, then push a*b.
: duplicate the stack top item.
~ swap the two top stack items.
_ pop the stack.
quit exit the REPL.
defun pop name, then turn the entire current stack into a function, and associate name with said function.
clear empty the stack.
any word prefixed by ' push the word without executing it (this is stackable).
exec pop the stack, and execute the popped value as a word.

you can read the source code for more info on what builtin words are available, or the example programs to get an idea of how programming this calculator works.

there's also the examples/ directory, which will contain small, specific examples. note that, while comments aren't actually supported, these examples might pretend that comments are supported. if so, they'll indicate single-line comments by starting the line with a #.

ideas

  • expose the doword internal function to the calculator. this would let programs modify its behaviour, for instance to make it possible to declare functions without quoting everything that you don't want to execute at function-construction-time.