Skip to content

garlic0x1/forth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple Forth interpreter made for fun.

Run the REPL:

(ql:quickload :forth)
(forth:run-forth)

FizzBuzz:

> def fizzbuzz 5 mod 0 = if "fizz" else "buzz" then end
FIZZBUZZ
> 16 4 do i fizzbuzz loop stack
(fizz buzz buzz buzz buzz fizz buzz buzz buzz buzz fizz buzz)

Lambdas can be placed on the stack with #(word1 word2):

> 1 #(1 +) stack
(#<FUNCTION (LAMBDA (SELF) :IN FORTH-EVAL) {10027FBF0B}> 1)
> call stack
(2)

Lisp interop:

> 1 (+ 2 3) + print
6 OK
> (uiop:hostname) stack
(garlic)

Native procedures can be implemented with define-forth, giving access to self

(define-forth +
  (incf (cadr (stack self))
        (pop (stack self))))

About

Experimental Forth interpreter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published