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))))