a small calculator written in Io.
Find a file
2023-11-01 14:18:42 +01:00
examples 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
functions.io separate core functions and operators into own files. 2023-11-01 14:18:42 +01:00
main.io separate core functions and operators into own files. 2023-11-01 14:18:42 +01:00
operators.io separate core functions and operators into own files. 2023-11-01 14:18:42 +01:00
program.txt add main demo program. 2023-10-31 17:44:06 +01:00
README.md add square example. 2023-10-31 18:12:15 +01:00

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.