On Friday, 10 February 2012 09:32:53 UTC, Gerry wrote:
> You omitted the next bit of the specification that the above refers to
> for semantics and which says (from
>
www.forth200x.org/documents/forth11-1.pdf):
>
> <quote>
> newname interpretation: ( i*x -- j*x )
> Perform the interpretation semantics of oldname.
> newname compilation: ( i*x -- j*x )
> Perform the compilation semantics of oldname.
> </quote>
>
> If oldname is immediate and an implementation doesn't make newname
> immediate then their compilation semantics are different which violates
> the second statement above.
>
Further, if a system has words with non-default and non-immediate semantics, shouldn't ' newname ( and ['] newname at runtime) return the interpretation semantics of oldname, and POSTPONE newname compile the compilation semantics of oldname, regardless of later STATE?
I'm beginning to see a way to Standardise such words, and still keep an interpreter that uses FIND:
: CLONE ( xt xtc ++ )
CREATE 2, IMMEDIATE
DOES> 2@ STATE @ 0= IF DROP THEN EXECUTE ;
CLONE? ( xt -- f ) system dependent. I /think/ you can always non-portably
recognize a DOES> word from its xt
: 'COMP ( ++ xt xtc ) FIND ?DUP 0= IF
COUNT TYPE [CHAR] ? EMIT ABORT THEN
-1 = IF
['] COMPILE ELSE
DUP CLONE? IF
>BODY 2@ ELSE
['] EXECUTE THEN ;
: ' 'COMP DROP ;
: ['] ' POSTPONE LITERAL ; IMMEDIATE
: POSTPONE 'COMP DUP ['] EXECUTE = IF
DROP ELSE
SWAP POSTPONE LITERAL THEN
COMPILE, ; IMMEDIATE
: & >IN @ >R 'COMP
R> >IN ! CLONE ;
: SYNONYM >IN @ >R BL WORD DROP \ skip new name for now
'COMP
>IN @ R> SWAP >R >IN ! CLONE
R> >IN ! ;
\ Gforth Style Combined Words
: ct>xtc ( ct -- xtc ) >R :NONAME POSTPONE DROP R> COMPILE, POSTPONE ; ;
: INTERPRET/COMPILE: ct>xtc CLONE ;
In general, whenever you want to decorate the behaviour of an already-defined word, clone it.