RETRO FORTH

Source Code
DOS | Windows | iOS | macOS

About

RETRO is a modern, pragmatic Forth drawing influences from many sources. It's clean, elegant, tiny, easy to grasp, and adaptable to many tasks.

It's not a traditional Forth. Drawing influence from colorForth, it uses prefixes to guide the compiler. From Joy and Factor, it uses quotations (anonymous, nestable functions) and combinators (functions that operate on functions) for much of the stack and flow control. It also adds vocabularies for working with strings, arrays, and other data types.

Documentation

Syntax Overview

Naming Conventions

Quotes and Combinators

Glossary (text)

Browse the Glossary

Features

Open Source

The source and documentation are distributed under the ISC license.

Portable

RETRO runs on a virtual machine. Implementations are provided in C, Python, Pascal, C#, JavaScript, and RETRO.

RETRO has been built and used on many systems including DOS, Windows, Linux, FreeBSD, NetBSD, Haiku, macOS, and iOS. Tested host CPU architectures include x86 (16 and 32 bit), x86-64, ARM, and PowerPC.

Self Contained

The standard binaries are entirely self contained and need only standard system libraries to run.

In addition, RETRO includes an interpreter that can make direct use of system calls to avoid even libc on FreeBSD, Linux, and macOS (x86, x86-64).

Small

RETRO is small, in both source and binaries.

A minimal C implementation of the VM is 641 lines, including commentary. The full implementation is 1,802 lines. On FreeBSD x86-64, the executable sizes range from 48KiB to 84KiB.

The language itself is written in assembly for the virtual machine and Forth, taking 1,232 lines and 35KiB. (The 35KiB image size is included in the binary as they embed a copy of the image.)

Code Sample

Sources in RETRO are in a literate format, using Markdown-style fenced code blocks.
~~~
[ 'Welcome 'To 'Retro ] set:make [ s:put sp ] set:for-each
~~~
Define a word (function) that removes vowels from a string:
~~~
:s:darken (s-) [ c:-vowel? ] s:filter ;
~~~
And test it:
~~~
'This_is_a_test_string s:darken
'Ths_s__tst_strng s:eq?
~~~
Thanks for taking a look at RETRO!
This is a quick and dirty way to find prime numbers in a set.
~~~
{{
  #2 'NextPrime var<n>
  :extract (s-s)
    [ @NextPrime dup-pair eq?
      [ drop-pair TRUE ]
      [ mod n:-zero? ] choose ] set:filter ;
---reveal---
  :get-primes (s-s)
    #2 !NextPrime
    dup fetch [ extract &NextPrime v:inc ] times ;
}}
~~~
And a test:
~~~
:create-set (-a)
  here #7000 , #2 #7002 [ dup , n:inc ] times drop ;

create-set get-primes [ n:put sp ] set:for-each
~~~
This site is served by Casket, an HTTP server written in RETRO.