home .. forth .. colorforth mail list archive ..

Re: [colorforth] Re: How is colorForth different from other Forths?


----- Original Message ----- 
From: "Samuel A. Falvo II" <kc5tja@xxxxxxxx>
To: <colorforth@xxxxxxxxxxxxxxxxxx>
Sent: Thursday, December 11, 2003 9:23 AM
Subject: Re: [colorforth] Re: How is colorForth different from other Forths?


> On Wednesday 10 December 2003 09:07 pm, Robert Patten wrote:
> >      Testing words in  Other Forths  leave a  true/false flag on the
> > stack for " if  " and  other branching
> > words   to remove and branch on false.
> >    In ColorForth   previous words may set/reset,  0 and minus
> > processor, flags for " if  "or -if   to branch
> > on false.  Or a testing word  that set or reset flag which  " if  "
> > uses to branch on false.   No other
> > branching words are necessary.
>
> You have to be careful about this though; this behavior is highly CPU
> dependent.  Currently, you'll find a lot of "<test> drop if" constructs
> in ColorForth's sources.  If, hypothetically, we port ColorForth to the
> 6809 or 6502 CPUs, this code will break, because "drop"  will silently
> change CPU flags.
>
> Moreover, even in x86 ColorForth, not all operations are known to set the
> flags.  Occasionally, you'll see the phrase "? if", where ? is a
> compiler word that emits "test eax,eax", an instruction that effectively
> is a no-op except that it sets the sign and zero flags based on what's
> in EAX (the register used to cache the top of stack; for those
> interested, having brought up the 6502 and 6809, it'd map to ORA #$00 in
> these architectures).
>

Is this a better comparison?

     Testing words in  Other Forths  leave a  true/false flag on the stack
for " if  " and  other branching
words   to remove and branch on false.
      In ColorForth " if  " does not drop.    No other branching words are
necessary.
      In  Pentium ColorForth   previous words may set/reset,  0 and minus
processor,   flags for " if  "or -if
to branch on false.    The Pentium  colorForth " drop " does not  change
flags allowing "<test> drop if" constructs.

> >     In ColorForth the new word is findable allowing recursion by
> > repeating the name or  a loop if followed
> > by ;  A previous word named the same,  in this word list is not
>
> You can also use RECURSE in classical Forth.
I appended it to the list.
>
> : chr
>   >r over c@ is-letter? if r> 1+ exit then r> ;
>
> : bump
>   >r 1- swap 1+ swap r> ;
>
> : lcnt
>   over 0= if nip nip exit then chr bump recurse ;
>
> : letterCount ( caddr u -- n ) \ Find the number of *letters* in string
>   0 lcnt ;
>
> Note: I deliberately ignored the use of a FOR or DO loop to prove a
> point.
>
> Given the same tail-call optimization rules that ColorForth has, the code
> the above produces would be correct according to ColorForth semantics.
> Therefore, one doesn't *NEED* to use BEGIN/AGAIN, WHILE/REPEAT, etc. in
> traditional Forth.
>
> What makes their use mandatory in traditional Forth is the traditional
> lack of tail-call optimization.  The above code would almost certainly
> break on most Forths with sufficiently long strings.  It also helps that
> we can use ; instead of EXIT -- less characters to type makes for easier
> code entry, which leads to less bugs (I can't tell you how many times
> I've accidentally entered ezit without realizing it).
>
Correction:

     In other Forths  a  word being defined is findable after definition
completion,   allowing a previous
definition to be included in current definition.  Making words like
"RECURSE  BEGIN  WHILE REPEAT
AGAIN " needed for logic flow.
    In ColorForth the new word is findable allowing recursion by repeating
the name or  a loop if followed
by ;  A previous word named the same,  in this word list is not findable.
Name objects and  " if then  ;
" are all that is necessary for logic flow.  A red  name  can be used for
entry at any point in definition  and
" if  ; "   to exit on true at any point  in definition before " then  ; "
exit on false. " If"  is the start of the
true phrase and " then" continue or false phrase.  ";" exits definition
jumping to previous word entry or
returning to next word  entry on the return stack.



> > In Forth  words like " .  ." .(  type emit dump " display a historical
> > view of portions of memory.
> > In colorForth,  any words after the last  executed show   is
> > repeatedly shown on the screen, overwriting
> > any history,  while the keyboard task accepts keys.
>
> This can be crudely emulated in ANSI Forth if, and only if, the return
> stack truely is a return stack:
>
> : show begin r@ execute pause again ;
>
> : myDisplayTask show page 5 5 at-xy foo @ ." Foo = " . ."    " ;
> : anotherTask begin ... 1 foo +! ... pause again ;
>
> ( ... somehow start the tasks here ... )
>
> You won't find very many tricks like this used in ANSI Forth, because
> ANSI claims the return stack is "OK" to not hold return addresses.
> Thus, there is no guarantee that it'll hold partial continuations.
>
> You also won't find very many tricks like this used in Scheme either,
> because Scheme does not support direct manipulation of partial
> continuations -- only complete continuations.  So while the above trick
> is possible in Scheme, it'd be horrifyingly inefficient if used in a
> deeply nested function.  Hence, if you want to run tricks like the above
> in Scheme, try as best you can to make it happen closest to global
> scope.
>
> > Character icons are arranged in
> > the icon table in Hoffman order to maximize the number of icons that
>
> The correct spelling is Huffman.  And while it's important to note that
> the characters are believed to be in Huffman order, their encoding is
> Shannon, not Huffman.

Correction:
In forth,  a line of Text from the keyboard  is buffered  and  after the
enter key is pressed, evaluated.
In  ColorForth  each key is mapped to a word and word performed now.     At
startup  the spacebar toggles from  text to number entry key maps,   shown
in lower right of the ColorForth window,    and puts 0  on stack.  The "alt"
key selects alternate base ( hex  or decimal)  the "n" key  negative number.
For each digit  top of stack is multiplied by the number base and then digit
added.    When finished with number entry,   toggle "space bar" back to the
text entry keymap,  leaving number on stack or removing the zero if no
number was entered then put a null text cell on the data stack.    Now "alt"
toggles between  two 24 character maps ( z and j keys are on the punctuation
and digit  map).   Character icons are arranged in  a  Shannon-Fano  order
in the icon table ,  to maximize the number of icons that can be stored in
the 28 bits available in the name  object field of a word.  The  4 to 7 bit
wide  index for this icon is right shifted into the cell on top of the stack
and  the 4  action bits  inserted.    Additional extenuation cells  may be
needed for a  long word.    When the  space bar is struck the first cell of
the word is found  in the forth  (user) wordset and performed.     This word
may  load ColorForth source pruning  and/or appending  source to the running
program.  Any word  name may be a just in time compiler of  ColorForth
source.  Because the program state is in the colorForth source,   the
program can be empty without loss of state.   When source is loaded again
the program will  resume state.  The desirable ColorForth program contains
only necessary words for the current computer activity and emptied and built
again  when current needs change. Interrupt word map or  key word map  or
word may cause program  needs to change causing the  running program to be
rebuilt, providing  the new current need.

>
> --
> Samuel A. Falvo II

Thank You for Your help.

Robert


---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com