[colorforth] Hello, World! and other simple programs
- Subject: [colorforth] Hello, World! and other simple programs
- From: Jeff Fox <fox@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 Jul 2001 11:07:09 -0700
- Organization: UltraTechnology
Kristopher Johnson wrote:
>
> Forgive me if these questions are too basic or have
> been addressed before. Without a mailing list archive,
> and without much traffic on the list, it's hard
> to determine exactly what everyone else is doing or has done.
> I intended to "lurk" for a while, but I don't see much happening...
I commented to your post in c.l.f and suggested that
the list would be a better place to ask questions
or provide links to your examples. There are
many people in c.l.f waiting for the opportunity
to look at a hex dump and post that ColorForth
is like programming in boxing gloves, or picking a
lock wearing boxing gloves using a strand of boiled
spaghetti for the pick, etc.
I haven't been able to get colorforth running on
a machine yet. I have thought of implementing
a version on F21 but would like to get a copy
running on a PC.
I like your wiki page and the colorforth source
displays.
The : nemit ( n [ n...] .. ) for emit next ;
seems very poor style instead of word like TYPE
that takes an address and count. Or better yet,
the address of a packed and counted string.
Putting each character on the stack first as
in : hello, 46 3 12 12 4 [ 20 cap ] 6 nemit ;
is just not how a stack should be used.
It isn't too bad for 6 items, stack cells are
to valuable to fill them up with data in that
style. Better to pass the address of a
counted packed string on the stack, or better
yet, pick it up inline using the return
stack pointer. There is a word to fetch
the value using the top of the return stack
and increment the pointer and it is an opcode
in Chuck's hardware and a machineforth
primitive that is good style.
make a word that works like ." except
compile the display-inlined-packed-string
subroutine followed by a packed counted string
compiled into the cells that follow the
subroutine call. The subroutine gets
the address from the top of the stack
and picks up the charters and displays
them. Internally it might have to hold a
few characters on the stack as it unpacks
them from memory. But the idea is with
something like that you write
." hello world" or something like that
and let the words do the packing and unpacking
and let the source code express the idea that
you want to enter a string and have it get
displayed at runtime by the compiled code.
Remember that the stack is not a big buffer.
Keep only what you need there. I have seen
Forth programmers start out by loading
hundreds of variables on to the stack then
initializing memory with them and I think
they missed the idea of how stacks are
used in Forth. I thought of P21 where there
are only 6 data stack cells total. You just
don't buffer strings or data arrays on
the stack, you keep the pointers and data
you are working on and try to keep it
to a minimum by using primitives instead of
more complex words. When you start to nest
your code the total stack usage goes up so
keep it as thin on each level as you can.
Since I have yet to play with ColorForth when
I looked at the code I think of Chuck's chips.
He does that also and it helps to frame the
ideas. On a Pentium one could buffer a book
as characters on the stack and build giant
stack frame arrays with megabytes in them
as is the fashion in the languages the chip
was designed to support, but that isn't
colorforth or machineforth style. I
remind you that the virtual machine and
primitives are the key to good colorforth
or machineforth.
I haven't played with your wiki pages. Perhaps it
would be good if a wiki like archive for the mail
lists could be created. This message will go out
to all list members and then they have a copy but
there is not an archive on the mail lists themselves
anywhere.
Jeff Fox
------------------------
To Unsubscribe from this list, send mail to Mdaemon@xxxxxxxxxxxxxxxxxx with:
unsubscribe ColorForth
as the first and only line within the message body
Problems - List-Admin@xxxxxxxxxxxxxxxxxx
Main ColorForth site - http://www.ultratechnology.com