From: Tim Vaughan Date: Tue, 26 Apr 2016 21:01:56 +0000 (+1200) Subject: Finished ROLL X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=forth.jl.git;a=commitdiff_plain;h=d2ce0337817800a06106ecc4943f10106739cf8b Finished ROLL --- diff --git a/src/lib.4th b/src/lib.4th index 781a966..f4b28e6 100644 --- a/src/lib.4th +++ b/src/lib.4th @@ -170,10 +170,6 @@ @ ( and fetch ) ; -: ROLL ( x_u x_u-1... x_0 u -- x_u-1 ... x_0 x_u ) - 1+ DUP PICK SWAP ( x_u x_u-1 ... x_0 x_u u+1 ) -; - ( With the looping constructs, we can now write SPACES, which writes n spaces to stdout. ) : SPACES ( n -- ) 0 DO @@ -316,3 +312,13 @@ THEN ; +: ROLL ( x_u x_u-1... x_0 u -- x_u-1 ... x_0 x_u ) + 1+ DUP PICK SWAP ( x_u x_u-1 ... x_0 x_u u+1 ) + PSP@ 1- SWAP - PSP@ 2- SWAP + DO + i 1+ @ i ! + LOOP + SWAP DROP +; + +