TYPE

( c-addr u -- )

If u is greater than zero, display the character string specified by c-addr and u.

When passed a character in a character string whose character-defining bits have a value between hex 20 and 7E inclusive, the corresponding standard character, specified by 3.1.2.1 Graphic characters, is displayed. Because different output devices can respond differently to control characters, programs that use control characters to perform specific functions have an environmental dependency.

See:

Testing:

ContributeContributions

NieDzejkobavatar of NieDzejkob Suggested reference implementationSuggested reference implementation2018-01-06 18:15:17

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

NieDzejkobavatar of NieDzejkobNew Version 2018-01-08 16:12:00

: 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 ;

alextangentavatar of alextangent 2018-01-08 16:12:31

: 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.

alextangentavatar of alextangent 2018-01-08 19:26:17

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

Reply