Digest #26 2018-01-09

Contributions

[49] 2018-01-08 17:54:46 NieDzejkob wrote:

referenceImplementation - Suggested reference implementation

: C, ( char -- ) HERE @ TUCK ! CHAR+ HERE ! ;

Replies

[r95] 2018-01-08 15:41:47 alextangent replies:

referenceImplementation - Suggested reference implementation

-ROT is not in the standard. A reference implementation should (must?) use standard words.


[r96] 2018-01-08 15:43:39 alextangent replies:

referenceImplementation - Suggested reference implementation

-ROT is not in the standard. A reference implementation should (must?) use standard words.


[r97] 2018-01-08 15:51:30 NieDzejkob replies:

referenceImplementation - Suggested reference implementation

Sorry, I could've sworn the previous implementation isn't there. Please ignore.


[r98] 2018-01-08 15:52:01 alextangent replies:

referenceImplementation - Suggested reference implementation

  1. This is not a correct definition; the closing ; is missing.
  2. It will only compile correctly if the 16 is interpreted as a decimal number, which the definition does not ensure.

[r99] 2018-01-08 15:54:04 NieDzejkob replies:

referenceImplementation - Suggested reference implementation

Sorry, my Forth is slightly non-standard in that regard.


[r100] 2018-01-08 16:03:12 NieDzejkob replies:

referenceImplementation - Suggested reference implementation

: FILL ( c-char u char -- ) ROT ROT 0 ?DO 2DUP C! CHAR+ LOOP 2DROP ;

The ROT ROT does not seem right to me, but finding anything better has proven not to be simple.


[r101] 2018-01-08 16:12:00 NieDzejkob replies:

referenceImplementation - Suggested reference implementation

: TYPE ( c-addr u -- ) 0 MAX 0 ?DO DUP C@ EMIT CHAR+ LOOP DROP ;

Alternatively, without ?DO or LOOP:

: TYPE ( c-addr u -- ) BEGIN DUP 0> WHILE OVER C@ EMIT [ -1 CHARS ] LITERAL - SWAP CHAR+ SWAP REPEAT 2DROP ;


[r102] 2018-01-08 16:12:31 alextangent replies:

referenceImplementation - Suggested reference implementation

: TYPE 0 MAX 0 ?DO DUP C@ EMIT 1+ LOOP DROP ;

should read

: TYPE ( c-addr u -- ) 0 MAX 0 ?DO DUP C@ EMIT CHAR+ LOOP DROP ;

There are several problems with (even the corrected version) as a reference implementation. The biggest issue is that it doesn't permit using the XCHAR wordset. The primitive for output there is XEMIT, and there is no equivalent XTYPE. The extension says "All words dealing with strings shall handle xchars when the xchar word set is present." It may be that there is no reference implementation in terms of standard words possible.


[r103] 2018-01-08 18:42:05 NieDzejkob replies:

referenceImplementation - Suggested reference implementation

Nope, this won't work, since HERE is more like a VALUE than a VARIABLE in ANS Forth. Why is standarization so hard?


[r104] 2018-01-08 19:09:21 alextangent replies:

referenceImplementation - Suggested reference implementation

: c, ( n -- ) here c! 1 chars allot ;

You're now running into chicken and egg problems. There aren't reference implementations for everything; some things are primitives qv DUP. You might want to stand back and work out those words that justify a reference implementation because they provide an explanatory point, and those that don't because they might be considered self evident. I'd contend that you've reached that point.


[r105] 2018-01-08 19:18:53 alextangent replies:

referenceImplementation - Suggested reference implementation

Consider not using ?DO

: FILL ( c-addr u char -- )
    >R BEGIN DUP 0<> WHILE
      OVER R@ SWAP C!
      1 /STRING
    REPEAT R> DROP ;

[r106] 2018-01-08 19:26:17 alextangent replies:

referenceImplementation - Suggested reference implementation

Addendum; and the use of 0 MAX is not correct, as the length of the buffer is unsigned.