Skip to content

An ugly and incomplete forth-like interpreter in scheme

Notifications You must be signed in to change notification settings

lirorc/sumterForth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 

Repository files navigation

sumterForth

An ugly and incomplete forth-like interpreter in scheme using just a single closure

Calling (forth) in the repl will call forth the interpreter.

Word definitions end with df instead of ;.

You can define a word like so -> : add1 1 + df

2 add1 will remove the 2 from the stack and put 3.

21 12 > if "North" else 12 21 < if "South" else "Canada?" then then will -hopefully- work.

Use .s instead of .S , dup instead of DUP and so on. The code is very incomplete so most things won't work.

If you need a loop, you have to use recursion.. which you can;

: show dup 0 = if "DONE" else dup . 1 - show then df

show 999999999 should print 999999999 999999998 999999997 etc.

: sum swap dup 0 = if drop "DONE" else swap + sum then df

0 12 23 34 45 sum should consume those numbers and put 114 to stack

: fact dup 0 = if drop "DONE" else dup rot * swap 1 - fact then df

: fac 1 swap fact df

5 fac should consume 5 and leave 120

You can pause the forth interpreter by typing pause, or you can exit and destroy the stack and defined words.

Q: Why forth

A: Because it's simple

Q: Why lisp

A: Because it's pretty

About

An ugly and incomplete forth-like interpreter in scheme

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages