Forth

Gforth

Installation

Ubuntu
apt install gforth
Arch Linux
yay -S gforth
Source Code

required emacs libltdl

# Download gforth-{version}.tar.gz from https://www.gnu.org/software/gforth/
tar xzf gforth-{version}.tar.gz
cd gforth-{version}
./configure [options]... [VAR=VALUE]...
make
make install

Examples

Fibonacci Numbers
\ Fibonacci Numbers

: fib ( n )
    dup 2 u< if exit then
    1- dup recurse swap 1- recurse +
;

fib . cr
bye

(
    example
        run:
            gforth -e 39 fib.fs
            gforth-fast -e 39 fib.fs
)

Iterative

\ Fibonacci Number
: fib ( n )
    dup 2 u< if exit then
    0 1
    rot 1 - 0 do
        2dup +
        rot drop
    loop
    nip
;

fib . cr

bye

(
    example
        run:
            gforth -e 39 fib.fs
            gforth-fast -e 39 fib.fs
)