Luke Gorrie (lukego) wrote,
Luke Gorrie

Forth is bliss

I'm programming in Forth on an exotic island and life is just fine. I've done two weeks of serious hacking now: the first to bring up Forth on the Keil MCB2100 board and the second to write drivers and make some extensions to Forth. Serious fun!

Forth is amazing. There's hardly any compiler or runtime system and yet it has all the sophistication of Lisp. This feels like discovering Gödel, Escher, Bach faithfully expressed in a few dozen cave paintings.

The best part about embedded programming is starting from scratch without using a single line of code that we didn't write outselves. Right now we don't have memory protection, dynamic memory allocation, concurrency, garbage collection, etc. So we're going to rediscover first-hand at what point it's worth developing these fancy features. Truly we're retreading some giant steps :-)

Here's some Forth I wrote that may be clever or stupid, I'm not sure which yet:

\ Running time profiling: t( ... )t
: t(
    r> tick      ( r t1 )
    >r >r        ( r: t1 r )
: )t
    tick r> r>   ( t2 r t1 )
    swap >r      ( t2 t1 )
    -            ( tdelta )
    . ." ms" cr
Ah the rapture of learning a new programming language :-)
Tags: forth
  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.