LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

forth

stack-based interactive programming language

TLDR

Start Forth interpreter (Gforth)
$ gforth
copy
Run Forth script
$ gforth [script.fs]
copy
Evaluate expression
$ gforth -e "[1 2 + .] [bye]"
copy
Include file then go interactive
$ gforth [script.fs] -
copy

SYNOPSIS

gforth [options] [file...]

DESCRIPTION

Forth is a stack-based programming language known for its simplicity and extensibility. Gforth is the GNU implementation of Forth, conforming to the ANS Forth standard.Forth uses reverse Polish notation (RPN) with an explicit stack. Words (functions) are defined with `:` and `;`. The language is highly interactive and extensible, commonly used in embedded systems.

PARAMETERS

-e code

Evaluate Forth code.
-m size
Dictionary size.
-d size
Data stack size.
-r size
Return stack size.
file
Forth source file to load.
-
Read from stdin.

BASIC OPERATIONS

$ \ Push numbers, add, print
2 3 + .   \ prints 5

\ Define a word
: square ( n -- n^2 ) dup * ;
5 square .   \ prints 25

\ Stack manipulation
1 2 3 swap   \ 1 3 2
dup          \ duplicates top
drop         \ removes top
copy

CAVEATS

Stack-based paradigm differs from most languages. Manual memory management. Limited standard library compared to modern languages. Debugging can be challenging.

HISTORY

Forth was invented by Charles H. Moore in the late 1960s for controlling radio telescopes. It became popular in embedded systems due to its small footprint and efficiency. Gforth was started in 1992 by Anton Ertl and Bernd Paysan.

SEE ALSO

dc(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid