- Fennel 84.2%
- Forth 15.8%
|
|
||
|---|---|---|
| .gitignore | Simplify arithmetic | |
| examples.forth | Hello, world | |
| forth.fnl | Accept file as an argument | |
| LICENSE | Add license | |
| README.md | Hello, world | |
| spellbook.forth | Chevrons look a bit nicer compared to quotes | |
forth.fnl - basically a calculator
This is a toy FORTH-like with a whole lot of Fennel in the soup. It's meant to help me understand the language and to have fun, too! This is meant to be used as a personal calculator so it might just be useful for me, but feel free to take what you need from it!
This is also being written by someone who's in the process of learning FORTH so this implementation is quite possibly composed of sins and tragedies in the eyes of actual FORTH programmers.
Running
To run, install Lua and Fennel. Try out the example file:
$ fennel forth.fnl examples.forth
What it can do
Import the standard library and print out a string:
« spellbook.forth » import
« hello, world! » say
You can define arbitrary words which can act as functions for your program.
( This is a comment )
: width 20 ;
: height width ;
: area width height * ;
( Print the result )
area say
It has some built-in words for calculations:
( Convert celsius to fahrenheit )
24 temp.celsiusToFahrenheit say
( Convert miles to kilometers )
15 dist.milesToKilometers say
You can print the stack by using the word stack.
You can also create variables:
( This defines the variables )
variable month
variable year
variable date
( Set multiple values by defining a word )
: setDate year ! date ! month ! ;
7 31 3 setDate
( Print multiple values by defining a word )
: showDate month @ « / » .. print
date @ « / » .. print
year ? ;
« The set date is » print showDate
License
ANTI-CAPITALIST SOFTWARE LICENSE (v 1.4)
This is anti-capitalist software, released for free use by individuals and organizations that do not operate by capitalist principles.
No AI
No AI was involved in making this. Fuck that.