Forth
v0.7.3
Forth
v0.7.3
Forth is a stack-based, concatenative programming language built around an explicit data stack and a dictionary of words. Instead of named variables and infix expressions, you push values onto the stack and apply words that consume and produce stack items, using postfix (reverse Polish) notation. CompileBytes runs GNU Forth (gforth) 0.7.3, a fast and portable Forth system with an interactive interpreter and compiler.
Programming in Forth means defining new words from existing ones, growing the language toward your problem. A word definition starts with : and ends with ; and runs by manipulating the stack. This minimal, extensible model historically made Forth popular for embedded systems, bootloaders, and resource-constrained environments. Its interactivity and tiny footprint make it an excellent vehicle for learning how stacks and threaded code work.
." Hello, World!" cr: square ( n -- n*n ) dup * ;
5 square . cr2 3 + . cr
10 4 - . cr: counts ( -- )
5 0 do i . loop cr ;
counts: sign ( n -- )
dup 0 > if ." positive" else ." non-positive" then drop cr ;
5 sign
-3 sign42 constant answer
variable total
10 total !
answer total @ + . cr: sum ( n -- sum )
0 swap 1+ 1 do i + loop ;
5 sum . cr: fact ( n -- n! )
dup 1 > if dup 1- recurse * else drop 1 then ;
5 fact . cr1 2 3 .s cr
swap .s cr
over .s crYes. CompileBytes runs gforth on the server, so you can define words and execute Forth code from your browser without installing a Forth system locally.
It uses GNU Forth (gforth) 0.7.3, a widely used, standards-oriented Forth with an interactive interpreter and a native-code compiler.
You can read a line with words like accept into a buffer, or read characters with key. Data you place in the stdin box is available to the running program through these input words.
Yes. GNU Forth is free software under the GNU GPL, and using it here on CompileBytes costs nothing.
Forth evaluates by pushing operands onto a data stack and applying operators that pop them, so 2 3 + leaves 5 on the stack. This stack model removes the need for parentheses and operator precedence.