Tuesday, May 21, 2013

Forth in Racket, Mind-bending and Beautiful

Jay McCarthy's efficient implementation of Forth in 85 lines of Racket is beautiful. It demonstrates how you can integrate two different programming paradigms in one environment, and it does so with some impressive macro-fu. Consider his goals:

  1. We must be able to define functions in Forth that are callable from Forth, always.
  2. We must be able to give functions stack effect annotations to enable them to be called from Racket.
  3. We must be able to lift Racket functions to Forth so they are oblivious to the stack, like turning + into :+.
  4. We must be able to lower Racket functions to Forth so they can directly affect the stack, like writing :over.
  5. We must be able to enter Forth from Racket arbitrarily, such as to write testing forms like check-forth.

Meeting all those goals is an impressive feat.

As a functional tool, I'm not sure I see much of a use for it (yet). As a novel case study and series of examples, it's fantastic.

No comments:

Post a Comment