RosettaCodeData/Task/Here-document/Forth/here-document-2.fth

29 lines
898 B
Forth
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

get-current get-order wordlist swap 1+ set-order definitions
: place over >r rot over cell+ r> move ! ;
: +place 2dup >r >r dup @ cell+ + swap move r> r> dup @ rot + swap ! ;
: count dup cell+ swap @ ;
set-current
CREATE eol 10 C, DOES> 1 ;
CREATE eod 128 ALLOT DOES> count ;
: seteod 0 parse ['] eod >body place ;
: start 0 0 here place ;
: read refill 0= IF abort" Unterminated here document" THEN ;
: ~end source eod compare ;
: store source here +place eol here +place ;
: slurp BEGIN read ~end WHILE store REPEAT refill drop ;
: totalsize here count + here - ;
: finish totalsize ALLOT align ;
: << seteod start slurp finish DOES> count ;
previous
( Test )
CREATE Alice << ~~ end ~~
They got a building down New York City, its called Whitehall Street,
Where you walk in, you get injected, inspected, detected, infected,
Neglected and selected.
~~ end ~~
Alice type bye