Digest #86 2019-10-04

Contributions

[121] 2019-10-03 14:30:28 ruv wrote:

referenceImplementation - Case-sensitivity independent implementation

If a Forth system can optionally turn on case-insensitivity, it does not affect by default [IF] ... [ELSE] ...[THEN] control structure in the provided reference implementation. The following implementation variant obeys the system's case sensitivity mode.

WORDLIST DUP CONSTANT BRACKET-FLOW-WL GET-CURRENT SWAP SET-CURRENT
: [IF]   ( level1 -- level2 ) 1+ ;
: [ELSE] ( level1 -- level2 ) DUP 1 = IF 1- THEN ;
: [THEN] ( level1 -- level2 ) 1- ;
SET-CURRENT

: [ELSE] ( -- )
   1 BEGIN BEGIN PARSE-NAME DUP WHILE
      BRACKET-FLOW-WL SEARCH-WORDLIST IF
         EXECUTE DUP 0= IF DROP EXIT THEN
      THEN
   REPEAT 2DROP REFILL 0= UNTIL DROP
; IMMEDIATE

: [THEN] ( -- ) ; IMMEDIATE

: [IF] ( flag -- ) 0= IF POSTPONE [ELSE] THEN ; IMMEDIATE 

Replies

[r337] 2019-10-03 11:33:36 ruv replies:

referenceImplementation - Reference implementation of SYNONYM

The standard says nothing about "STATE-smart words" in the normative parts. How can you infer from the standard that the existing reference implementation is broken? It seems for me that this implementation does not violate the specification for SYNONYM word.


[r338] 2019-10-03 12:09:02 ruv replies:

testcase - Test cases for SYNONYM

An incorrect test cannot show that an implementation is incorrect.

The following test is incorrect:

t{ 1 2 ' my-+ ]execute[ -> 3 }t

Tick returns an identifier for execution semantics, but according to the specification, execution semantics is not defined for the words that created via SYNONYM. Therefore you try to test undefined behavior.

And even the controversial clause "When interpreting, ' xyz EXECUTE is equivalent to xyz"[1] does not support this test since ]execute[ is not equivalent to EXECUTE.

Also, the result of the following test cannot be forecast from the reference implementation:

t{ : comp-my+ postpone my-+ ; -> }t
t{ : ya-+ [ comp-my+ ] ; -> }t
t{ 1 2 ya-+ -> 3 }t

Since depending on implementation of POSTPONE it can be success or failed. Therefore, this test cannot refute the reference implementation, since in some Forth system (with this reference implementation) this test can be success.


[1] From 6.1.0070. This clause actually represents merely the default interpretation semantics, see 3.4.3.2.