home .. forth .. misc mail list archive ..

Color Forth


Jeff Fox wrote:
> He made other points about Forth and where he want to go
> with it.  He wants to simplify it further.  He wants to
> replace words like : ; ( ) COMPILE [COMPILE] IMMEDIATE etc
> with a color change token that just looks like a space.

I find Chuck's idea very interesting.  The only use of color I've seen
in source code was augmentation of the standard syntax, not
replacement.  Ie. the editor in Borland's Turbo C++ 3.1 IDE shows C++
keywords in bold black, numbers in green, comments in italicized blue,
and illegal syntax in red (if I remember correctly).  The source code
itself is plain ASCII text; there aren't any special color commands
embedded in the text.  This helps when writing/debugging source code. 
But color doesn't have any meaning to the compiler; it is just there for
the visual effect for the programmer.  I've never heard of color
actually being used by the computer before.
It seems to me that Chuck is missing something obvious.  The computer
does not actually deal with colors. It deals with raw data.  Chuck's
Color Forth source code contains embedded codes which trigger various
colors on the display.  The compiler actually looks at these embedded
codes and uses them the same way a standard Forth would use a colon, a
semicolon, etc. in the source code.  One could just as easily write a
special text editor that _visually_ eliminated all the colons and turned
words immediately following those colons into red text; the editor would
thus consider a colon to be an embedded command meaning "make the next
word red".  This would have the same visual effect as Chuck's color
Forth but would not have to make use of a new syntax; while he insists
on replacing colon with a special character that represents "red" (or
whatever color he's using), it would make much more sense to use a colon
as that "special character" and have your editor simply "hide" all of
the colons and visually display words after colons in red.  This way,
you get the visually appealing display that he likes (and yes, there's a
possibility it would make programming easier), yet you retain the
well-known (and easy to remember) syntax of standard Forth in your
actual source code, no matter how you choose to display that source code
on the screen.
Example:  Suppose I have the following lines in my source code.  It
would appear exactly as-is in a normal text editor.

: square  ( x -- x' )  dup * ;
: sqrt  ( x -- x' )  ( Square root not implemented yet.) ;
code arctan  ( x y -- theta )
   \ A machine coded pre-calculated lookup-table would be best here.
   end-code
: xy>r  ( x y -- r )  \ Calculate hypotenuse length from side lengths.
   square swap square + sqrt ;
: rec>polar  ( x y -- r theta )
   2dup  xy>r  rot rot  arctan ;

That code would show up as follows in the special color editor,

square   x -- x'   dup *
sqrt   x -- x'   Square root not implemented yet.
arctan   x y -- theta
    A machine coded pre-calculated lookup-table would be best here.
xy>r   x y -- r   Calculate hypotenuse length from side lengths.
   square swap square + sqrt
rec>polar   x y -- r theta
   2dup  xy>r  rot rot  arctan

with the first occurances of square, sqrt, xy>r, and rec>polar appearing
in red, all of the comments appearing in blue, the first occurance of
arctan appearing purple, and everything else appearing black.  With this
solution, the same source code can be used in both a regular editor and
a color editor.  Chuck's solution, in contrast, would give exactly the
same appearance in the color editor, but would NOT have normal Forth as
the underlying source code.

--Andrew
asieber@usa.net