Re: The IMMEDIATE mess



In article <12f81n5mc01btf2@xxxxxxxxxxxxxxxxxx>,
Andrew Haley <andrew29@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
<SNIP>

OK. It seems to me that IMMEDIATE does this job quite well already:
if you have a word that only makes sense in compile state (e.g. IF,
WHILE, etc) then what is wrong with IMMEDIATE ? IMMEDIATE has just
one job to do.

IF and other control words working in interpreted state results in
this beautiful one-screener:
------------------8<----------------------------------
( CRC-MORE CRC ) CF: ?32 \ AvdH
REQUIRE BOUNDS REQUIRE NEW-IF HEX
\ Well the polynomial
EDB8,8320 CONSTANT CRC32_POLYNOMIAL

\ Auxiliary table with values for single bytes.
CREATE CRCTable
100 0 DO I 8 0 DO
DUP >R 1 RSHIFT R> 1 AND IF CRC32_POLYNOMIAL XOR THEN
LOOP , LOOP
\ For initial CRC and BUFFER COUNT pair, leave the updated CRC
: CRC-MORE BOUNDS DO DUP I C@ XOR 0FF AND CELLS CRCTable + @
SWAP 8 RSHIFT XOR LOOP ;
\ For BUFFER COUNT pair, leave the CRC .
: CRC -1 ROT ROT CRC-MORE INVERT ;
DECIMAL
------------------8<----------------------------------

This does a full zip-compatible crc as per
S" monkey.frt" GET-FILE ( alias SLURP ) CRC HEX .

Languages like c have to run a special program to generate
tables, then include those huge tables in the actual
program.
Forth generates the table during compilation.

<SNIP>

I'm sorry, this is all too abstract for me. I guess I don't
understand what the problems are you're trying to eliminate; in the
absence of any examples I have no way to know. I know what I think
should go: STATE. At the time of ANS, Forth, Inc already had
well-established practice for a STATE-free Forth, but STATE went into
the standard anyway.

The following is not to say that I'm font of the word STATE per se.

I hate people talking about state-free Forth, and not realising
that numbers are state smart, indicating that you can't get rid
of some form of state altogether.
The only one to get it right (from the purist point of view,
at least) is Chuck Moore.
He attaches state to each instance of usage of a word, not to the
word itself.
He has different colors for numbers whether they must be compiled or
put on the stack and different colors for words when they are to be
executed, or compiled, or defined.


Andrew.


--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
albert@xxxxxxxxxxxxxxxxxx http://home.hccnet.nl/a.w.m.van.der.horst
.



Relevant Pages

  • Re: The IMMEDIATE mess
    ... <SNIP> ... if you have a word that only makes sense in compile state (e.g. ... LOOP, LOOP ... \ For initial CRC and BUFFER COUNT pair, ...
    (comp.lang.forth)
  • Re: The IMMEDIATE mess
    ... Usually what we need is not IMMEDIATE words or state-smart words. ... Any word that includes POSTPONE or executes COMPILE, ... The issue doesn't come up after you execute the words. ...
    (comp.lang.forth)
  • Re: The IMMEDIATE mess
    ... You do better to treat almost every immediate word as ... makes sense in compile state, then you can make it with IMMEDIATE. ... But there's no way for a standard program to do either ... line of standard code that has an IMMEDIATE in it. ...
    (comp.lang.forth)
  • Re: The IMMEDIATE mess
    ... You do better to treat almost every immediate word as ... makes sense in compile state, then you can make it with IMMEDIATE. ... But there's no way for a standard ... If you give Forth programmers power, ...
    (comp.lang.forth)
  • Re: The IMMEDIATE mess
    ... makes sense in compile state, then you can make it with IMMEDIATE. ... In 35 years I've yet to have a problem with IMMEDIATE. ... So I want to find a way to add the features I want instead of get rid ... If you give Forth programmers power, ...
    (comp.lang.forth)