Level 3, lesson 13

# 3.13 Other Return Stack manipulations

The Return Stack can avoid some complex stack acrobatics. Stack acrobatics? Well, you know it by now. Sometimes all these values and addresses are just not in proper sequence, so you have to 'SWAP' and 'ROT' a lot until they are.

You can avoid some of these constructions by just moving a single value on the Return Stack. You can return it to the Data Stack when the time is there. Or you can use the top of the Return Stack as a kind of local variable.

No, you don't have to move it around between both stacks all the time and you don't have to use 'I' out of its context. There is a well-established word, which does the same thing: 'R@'. This is an example of the use of 'R@':

         : delete                           ( n --)
              >r #lag +                     ( a1)
              r@ - #lag                     ( a1 a2 n2)
              r@ negate                     ( a1 a2 n2 n3)
              r# +!                         ( a1 a2 n2)
              #lead +                       ( a1 a2 n2 a3)
              swap cmove                    ( a1)
              r> blanks                     ( --)
         ;

'R@' copies the top of the Return Stack to the Data Stack. This example is taken from the 4tH-editor. It deletes "n" characters left of the cursor. By putting the number of characters on the Return Stack right away, its value can be fetched by 'R@' without using 'DUP' or 'OVER'. Since it can be fetched at any time, no 'SWAP' or 'ROT' has to come in.