Path: ...!goblin3!goblin.stu.neva.ru!sewer!alphared!news.uzoreto.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: ANN: STATE-smartness: Applications, Pitfalls, Alternatives
Date: Sat, 24 Oct 2020 17:13:14 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 90
Message-ID: <2020Oct24.191314@mips.complang.tuwien.ac.at>
References: <2020Sep25.172123@mips.complang.tuwien.ac.at> <rlomqq$4pk$1@dont-email.me> <6-6dnfkDx-5shR7CnZ2dnUU78RfNnZ2d@supernews.com> <rm52fq$gbo$1@dont-email.me> <FvedndM7l9hhIBvCnZ2dnUU78VvNnZ2d@supernews.com> <rm6rcm$ikr$1@dont-email.me> <sq6dnTLNbtWPshrCnZ2dnUU78YnNnZ2d@supernews.com> <rmc47c$qeb$1@dont-email.me> <n4OdncFG84JbJhfCnZ2dnUU78YXNnZ2d@supernews.com> <rmtijn$i52$1@dont-email.me> <2020Oct23.191207@mips.complang.tuwien.ac.at> <rn0333$ice$1@dont-email.me>
Injection-Info: reader02.eternal-september.org; posting-host="ee442f298e7b4c4e0071d7d39af48599";
	logging-data="28121"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/nhofeDcIiEEg9mgjtcbUp"
Cancel-Lock: sha1:HJM9zpqR+3lQSfBbCuCzqfzPQ2s=
X-newsreader: xrn 10.00-beta-3
Bytes: 5363

Ruvim <ruvim.pinka@gmail.com> writes:
>On 2020-10-23 20:12, Anton Ertl wrote:
>
>> Forth-94 (and, by extension, Forth-2012) are intended to support a
>> variety of implementation approaches, in particular the traditional
>> single-xt+immediate-flag one and the dual-wordlist approach of
>> cmForth.  The way it is specified leads to the idea of a dual-xt system.
>
>
>> There are a few issues that are problematic for one approach or
>> another:
>> 
>> * FILE S" cannot be implemented on a single-xt+immediate-flag system.
>>    Possible solutions: Only implement core S" on such systems, or
>>    propose a restriction in the standard that would allow it.  In
>>    practice, the implementors of these systems don't implement a
>>    standard S".

Actually, it can be implemented on such a system as follows:

: s"-int ... ; \ implements the interpretation semantics
: s"-comp ... ; \ implements the compilation semantics
: s" state @ if s"-comp else s"-int then ; immediate
: ' ' dup ['] s" = if drop ['] s"-int then ;
: postpone
  bl word find dup 0= -13 and throw
  0< if postpone literal postpone compile, exit then
  dup ['] s" = if postpone s"-comp exit then
  compile, ; immediate

>Anton, what makes you think that my implementation of FILE S" on a 
>single-xt+immediate-flag system is non standard?  https://git.io/JvctZ

Looks ok for POSTPONE.  ' S" produces a state-smart xt, but that can
be fixed in the same way.

>This implementation can be even loaded in Gforth

Any other Forths with "LIT," around?  And even in Gforth you have to
use something newer than 0.7:-).

>> * FIND has an interface that naturally fits a single-xt+immediate-flag
>>    system.  However, the standard caters for other systems by allowing
>>    FIND to be STATE-dependent.  And that's the solution for the other
>>    systems.  In particular, if you have a pure dual-xt system, FIND
>>    returns xt-int (and either -1 or 1) in interpret state and returns
>>    xt-comp and 1 in compile state.
>
>Such a pure dual-xt system would be non standard.
>
>The standard says that FIND returns execution token for given word. In 
>the cases when the execution semantics for the word are specified, this 
>token shall identify namely these semantics, independently of the STATE. 
>Since any variance can be detected by a standard program. It means that 
>in a standard system FIND cannot return ( xt-comp 1 ) in compile state 
>for ordinary words.

However, the standard also specifies

|For a given string, the values returned by FIND while compiling may
|differ from those returned while not compiling.

In addition, the rationale of FIND says:

|One type 3 implementation, Charles Moore's cmForth, has both compiling
|and interpreting versions of many Forth words. At the present, this
|appears to be a common approach for type 3 implementations. The
|committee felt that this implementation approach must be
|allowed. Consequently, it is possible that words without
|interpretation semantics can be found only during compilation, and
|other words may exist in two versions: a compiling version and an
|interpreting version. Hence the values returned by FIND may depend on
|STATE, and ' and ['] may be unable to find words without
|interpretation semantics.

cmForth implemented a lot of words where execution semantics are
specified, e.g., +, as immediate words in the compiler wordlist.  So
it clearly was not the intention of the Forth-94 committee that the
execution token returned by FIND can only be the xt representing the
execution semantics.  And that the allowance to return different xts
includes words with execution semantics.

More tomorrow.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2020: https://euro.theforth.net/2020