Wednesday, December 27, 2006

Typing ColorForth...ver 2.0

Hello folks. Back fresh from the forever flamewars at comp.lang.forth. :) It's funny how some people want to nitpick ColorForth while posting code that the ANS standard calls "dangerous".

Anyway the current "nitpick" is over my stype code. Small confession. I'm not omniscient. ;) When I posted at c.l.f. I was replying to the usual nonsense while thinking about where I was going with PrimaryForth tutorial as opposed to just answering what's possible now. Once I get finished you will be able to do the following code:

s 0 hello , i speak forth
ok show text s stype ;

And get:

hello, i speak forth

as output. Right now you get:


as output. If you want to get the entire phrase you have to put the number of words you want to type on the stack use the "words" word. For example:

ok show text s 5 words ;

I really don't see that as a big deal. You still don't have to do:

show blue screen text 230 350 at red 2a 10 c 1 3 3f 0 2e 3 c c 4 44 13 for 2emit next ; hw

But don't tell the "haters*" that. :) They still want to believe what they want to believe. Still, I've found a way around this. By storing the number of words in the ColorForth string variable (the same as the way ANS Forth stores the number of charecters in the first byte of an ANS Forth string variable) the computer can put the number of words on the stack for you. For example:

s 5 hello , i speak forth
phrase dup @
words for ntxtw next ;

Now with just one small line of ColorForth:

ok show text s phrase ;

You get:

hello , i speak forth

The next step will be to incorporate testing the token color. Comments use the "white" color. So phrase could be programmed to typing words until it hits a word that's not a comment. (Thanks to "tathi" on the c4th IRC channel for kicking this idea around.)

* Note: By "haters" I don't mean the person who actually wrote the ColorForth code I referenced. I mean those who want to insist on using that as "proof" that it's difficult to do something as simple as "hello world" in ColorForth rather than seeing the obvious. ColorForth, like any other Forth, is extensible.

No comments: