Caveats
- I'm hoping to talk about colorForth in the large
- I want to talk about the potent ideas in Chuck's explorations
- I have an incomplete view of Chuck's work
Introduction
- Chuck's work has always been about "Decomplexifying"
- Software and hardware is SO complex now
- But kilobytes still matter, and everything is so slow
- We really need to find a better way to write software!
- The ideas in colorForth point the way
Note about Colors
- word - define
- word - compile
- word - execute
- 1234 - execute numbers
- word - variable
- word - force compile
- word - decorate
- - comment
Note about Colors
For older slides
- word - define
- word - compile
- word - execute
- 1234 - execute numbers
- - comment
Don't get distracted by color
- colorForth
isn't about syntax highlighting or a neat alternate visualization
- It's not about the eclectic editor
- It's informed by making Forth even simpler
colorForth Chronology
- Precursors (1970-1997)
- iTV Era (1998-20??)
- GreenArrays Era (20??-2015)
- uhdForth (2016-present)
What is Forth?
In 1999 Chuck said:
- Highly factored code
- Definitions
- Stacks (to support definitions)
What is a definition?
In 1999 Chuck said:
- : SOME ... ;
- an abbreviation
- should never have more than 1-2 arguments
- stack should never be more than 3-4 deep
You can write FORTRAN in any language
- Forth is powerful, it lets you define any syntax
- There's a temptation to borrow from other languages
- locals, exceptions, structures, scopes, types
- "Find the hundred words to solve you problem in one line."
DEA- FIG,
I AM A FOR-- PRO------- CUR------
EMP----- BY FOR-- INC. I HAV- NOT
WOR--- ON ANY FIG TYP- SYS---- AND I
AM EXC---- BY THE VAR----- LEN---
NAM- IDE-. PLE--- SEN- ME THE FIG
FOR-- MOD-- SO THA- I MAY TRY IT OUT
HER- AT FOR-- INC.
FRE- THO----
Forth Dimensions Volume 2 Number 6
DEAR FIG,
I AM A FORTH PROGRAMMER CURRENTLY
EMPLOYED BY FORTH INC. I HAVE NOT
WORKED ON ANY FIG TYPE SYSTEMS AND I
AM EXCITED BY THE VARIABLE LENGTH
NAME IDEA. PLEASE SEND ME THE FIG
FORTH MODEL SO THAT I MAY TRY IT OUT
HERE AT FORTH INC.
FRED THORTON
Forth Dimensions Volume 2 Number 6
DEA- EDI---
I AM AFR--- THA- THE LET--- IN THE LAS- ISS-- ABO--
FOR-- INC- USI-- ONL- THR-- LET--- NAM- FIE--- HAS
HAD THE OPP----- EFF--- FRO- WHA- THE WRI--- WAN---
HIS LET--- ( LIK- THI- ONE ) SHO-- THA- SAV--- ONL-
THR-- LET---- AND COU-- IS JUS- ABO-- OPT---- IN
TER-- OF A TRA-- OFF BET---- SAV--- MEM--- AND
KEE---- LEG--------
YOU-- TRU--
CHU-- MOO--
FOR-- INC-
P.S- MR. FRE- THO---- IS NOT AN EMP----- OF
FOR-- INC-
Forth Dimensions Volume 3 Number 1
DEAR EDITOR
I AM AFRAID THAT THE LETTER IN THE LAST ISSUE ABOUT
FORTH INC. USING ONLY THREE LETTER NAME FIELDS HAS
HAD THE OPPOSITE EFFECT FROM WHAT THE WRITER WANTED
HIS LETTER ( LIKE THIS ONE ) SHOWS THAT SAVING ONLY
THREE LETTERS AND COUNT IS JUST ABOUT OPTIMAL IN
TERMS OF A TRADE OFF BETWEEN SAVING MEMORY AND
KEEPING LEGIBILITY.
YOURS TRULY
CHUCK MOORE
FORTH INC.
P.S. MR. FRED THORTON IS NOT AN EMPLOYEE OF
FORTH INC.
Forth Dimensions Volume 3 Number 1
Why was standardizing Forth hard?
- Forth is more complex than it seems
- Dictionary: links, vocabulary hooks, variable length entries
- You can't even define Forth dictionary entries statically in C!
- Fig-Forth had 221 words, not including internals
Early colorForth
- 6 Colored spaces: define, compile, execute, excute number, preceed words
- 4 x 3 "stack" of word colors
- Interpret / compile is table dispatch
- square dup * ;
Why is this simpler?
- Compilation and interpretation is more uniform
- How to parse: number / lookup is explicit
- Ambivalence about IMMEDIATE words
EMPTY VARIABL
E BUF W H : ROW A! 1
59 BEGIN @+ IF + ; T
HEN DROP NEXT 0 ; RO
WS DUP BUF ! ROW IF
DROP DROP ; THEN DRO
P -1 H +! DUP A + R
OWS ; 448 H ! VGA 0
OVER ROWS -1280 SWAP
640 447 * + ROWS
EMPTY VARIABL
E BUF W H : ROW A! 1
59 BEGIN @+ IF + ; T
HEN DROP NEXT 0 ; RO
WS DUP BUF ! ROW IF
DROP DROP ; THEN DRO
P -1 H +! DUP A + R
OWS ; 448 H ! VGA 0
OVER ROWS -1280 SWAP
640 447 * + ROWS
EMPTY
VARIABLE BUF W H :
ROW A! 159 BEGIN @+ IF + ; THEN DROP NEXT 0 ;
ROWS DUP BUF ! ROW IF DROP DROP ; THEN
DROP -1 H +! DUP A + ROWS ;
448 H ! VGA 0
OVER ROWS -1280 SWAP
640 447 * + ROWS
Address Registers
- A! - Store to A
- A - Get value of A
- @+ - Read from A and increment
- !+ - Store to A and increment
Less Greedy Conditionals
- IF doesn't consume its argument
- Avoids DUPs
- -IF - Tests sign bit
Simpler flow control
- DO .. LOOP - 2 parameters and just too complicated
- FOR .. NEXT - 1 parameter, good for hardware
- BEGIN .. UNTIL - variable num params
- WORD: ... IF ... WORD ; THEN ... ; - seems to be adequate
- Needs recursive definitions, no smudge
- Tail recursion
Howerd Oakford
- Howerd worked hard to make colorForth easier to run and more accessible
- https://www.inventio.co.uk/cf2023/index.html
- Thanks Howerd!
Example: Fibonacci Numbers
fib push 1 dup pop -2 +
f -if drop nip ; then
push swap over + pop -1 + f ;
8 fib
Example: Fibonacci Numbers
: fib ( n -- n ) >r 1 1 r>
1- for swap over + next drop nip ;
8 fib
Pre-parsed Words
Shannon Coded Words
Why is this awesome?
- One word = one machine word
- Dispatch is now even more trivial, mask and call
- Parse numbers at edit time
- Dictionary is two arrays
The compiler / interpreter
: eval ( a n -- )
for
dup @ dup untag execute 1+
next drop ;
Parts of the system
- dispatcher
- dispatch word per color: number unpacks, define adds to dict, compile adds a call, execute calls
- editor happens beforehand
- seed the dictionary with basic words
Why aren't we all doing this?
- Chuck's implementation doesn't work where we want it
- Which conventions do we adopt?
- Which source conventions do we adopt?
Quirks of "standard" colorForth
- Limitations on name encoding
- Two vocabularies only (forth + macro)
- Definitions drop through
- Literal on execute to compile
- No standard loops
- IF preserves stack
- -IF in place of 0< IF
- No ELSE
MORE Quirks of "standard" colorForth
- >R R> become push pop
- A! A @+ etc.
- @ ! use indexes instead of addresses
- Requires special editor
- Loss of CREATE DOES&rt;
- Unclarity around allocation
Why have I been stuck?
- My RainbowForth was too complex
- I got stuck on trying to match colorForth conventions
- How to sensibly interface with "normal" things?
- Source control, github
Why have I been stuck?
- Subroutine threading is hard
- Color constrains what kind of environment
- Is it a Turing Tar Pit?
- Macro vocabulary or not?
- Can it be even simpler? No compiler, just an editor
What is Chuck grappling with?
- Running on Windows
- Avoiding non-explicit macros
- Wants to touch the machine code
- Keeps vacilating on if source is needed
How can we take this somewhere?
- Pick a source format + build something?
- Pick a target? ESP32-colorForth?
What's great with it?
- Editors really are easy to write
- Forth interpreters are harder, less in Forth
- Strings are messy, we haven't found a great vocabulary for them
Proposal
- Try to write simple easy short definititions ;
- Think about how to live without: vocabularies, locals, strings, files, unicode, complexity, CREATE DOES>, objects
- Come back with something useful