?

Log in

No account? Create an account
Forth school - Luke's Weblog [entries|archive|friends|userinfo]
Luke Gorrie

[ website | My Website ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Forth school [May. 22nd, 2009|07:32 am]
Luke Gorrie
[Tags|, ]

I went to Forth school with Mitch Bradley yesterday. Here are a few cool new things I learned:
  • many: The word many repeats execution of the current line until a key is pressed.
    ok ." luke rules" cr  many
    luke rules
    luke rules
    luke rules
    
    ok see many
    : many   
       key? 0= if    
          0 >in ! 
       then  
    ; 
    
  • quine: Since we can introspect the input stream it's easy to write a program that prints itself to stdout.
    ok ( this is a quine ) source type
    ( this is a quine ) source type
    
  • patch: The word patch is a simple way to make binary patches to Forth words.
    ok : foo 1 + ;           
    ok see foo
    : foo   
       1 + 
    ; 
    ok 41 foo .
    42 
    
    ok patch - + foo
    ok see foo
    : foo   
       1 - 
    ; 
    ok 43 foo .
    42 
    
    ok patch 5 1 foo
    ok see foo
    : foo   
       5 - 
    ; 
    ok 47 foo .
    42 
    ok 
    
I love Forth.
LinkReply

Comments:
[User Picture]From: darius
2009-05-22 07:13 am (UTC)
many is cute. Funny how seeing "1 +" instead of "1+" still makes me twitch after so many years of no Forth.
(Reply) (Thread)