RosettaCodeData/Task/Reverse-a-string/Forth/reverse-a-string-2.fth

8 lines
315 B
Forth
Raw Permalink Normal View History

2020-02-17 23:21:07 -08:00
\ reverse a string using the data stack for temporary storage
2015-11-18 06:14:39 +00:00
2020-02-17 23:21:07 -08:00
: mystring ( -- caddr len) S" ABCDEFGHIJKLMNOPQRSTUVWXYZ987654321" ;
2015-11-18 06:14:39 +00:00
2020-02-17 23:21:07 -08:00
: pushstr ( caddr len -- c..c[n]) bounds do I c@ loop ;
: popstr ( c.. c[n] caddr len -- ) bounds do I c! loop ;
: reverse ( caddr len -- ) 2dup 2>r pushstr 2r> popstr ;