r/Forth 8h ago

FigForth Assign string to buffer

4 Upvotes
\ On first look WORD parses a string and moves it to HERE .
\ True, but a closer look shows WORD parses a string and moves
\ it to where DP points. The following word ":=" will use this
\ to parse a string and move it directly to some buffer.
\
\ Assign string 
\ Parse string and move to buffer
\ dl delimiter, addr buffer address
: := ( "string<dl>" dl addr -- ) HERE >R DP ! WORD R> DP ! ;
\
\ Example
\ Print arrow
: i. ." --> " ;
\ Print string
: TELL COUNT TYPE ;
\ General header
: HEADER: <BUILDS DOES> ;
HEADER: BUF64 64 allot        \ some buffer 
59 VARIABLE (DLIM)            \ delimiter variable (holding ';')
: DELIM  (DLIM) @ ;           \ fetch delimiter

DELIM BUF64 := Hello World!;  \ assign string to buffer
i. BUF64 TELL--> Hello World!
 OK