FILL

( c-addr u char -- )

If u is greater than zero, store char in each of u consecutive characters of memory beginning at c-addr.

Testing:

T{ FBUF 0 20 FILL -> }T
T{ SEEBUF -> 00 00 00 }T

T{ FBUF 1 20 FILL -> }T
T{ SEEBUF -> 20 00 00 }T

T{ FBUF 3 20 FILL -> }T
T{ SEEBUF -> 20 20 20 }T

ContributeContributions

NieDzejkobavatar of NieDzejkob Suggested reference implementationSuggested reference implementation2018-01-06 18:08:55

: FILL -ROT 0 ?DO 2DUP C! 1+ LOOP 2DROP ;

alextangentavatar of alextangent 2018-01-08 15:41:47

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

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

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

alextangentavatar of alextangent 2018-01-08 19:18:53

Consider not using ?DO

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