mirror of
https://git.sr.ht/~crc_/retroforth
synced 2024-11-16 19:48:56 +01:00
848ba7303b
FossilOrigin-Name: b5feea667d30aac255d1cfca61fed355d438d2ce6021677f1e53af6302b15eee
22 lines
383 B
Text
22 lines
383 B
Text
# Save and Restore Stack
|
|
|
|
It's sometimes useful to temporarily save and restore the entire
|
|
stack. These two words allow for this.
|
|
|
|
## The Code
|
|
|
|
~~~
|
|
:stack:save (-a)
|
|
here [ depth dup , &, times ] dip ;
|
|
|
|
:stack:restore (a-)
|
|
&reset dip
|
|
dup fetch over + swap fetch [ dup fetch swap n:dec ] times drop ;
|
|
~~~
|
|
|
|
## Test Case
|
|
|
|
```
|
|
#1 #2 #3 #4 #5
|
|
stack:save #3 swap stack:restore
|
|
```
|