Forth school

May 22, 2009 07:32


Read more... )

olpc, forth

Leave a comment

Comments 3

darius May 22 2009, 07:13:17 UTC
many is cute. Funny how seeing "1 +" instead of "1+" still makes me twitch after so many years of no Forth.

Reply


(The comment has been removed)

ext_94217 May 28 2009, 20:12:44 UTC
Er...not quite. >IN is a variable which tells where the interpreter is in the current line. It doesn't have anything to do with KEY?, which returns a flag telling whether keyboard input is available. So 0 >IN ! resets the interpreter to the beginning of the line, and KEY? 0= IF ... THEN says "do this if no key has been pressed."

Reply

(The comment has been removed)

ext_94217 May 29 2009, 13:18:51 UTC

No, it's just for use interactively. Maybe as a debugging aid or something? Probably just a cute trick.

Well...you could put it in another definition, but it's not a compiled looping construct, it would just cause that word to behave like many. That is, when it is interpreted it would send the interpreter back to the beginning of the line. And of course it wouldn't have any effect until the word returns, so it wouldn't (usually) matter where in the definition you put it. Here's a lousy example: :-)

: count-up dup . many cr 1+ ;

17 ( need a line-break here; you don't want to do 17 every time )
count-up

18
19
20
... until you press a key

--Josh

Reply


Leave a comment

Up