How can I get the number of elements currently held in the stack in Forth?
I ask this because I want to make a function that prints out all the elements of the stack, something like:
: pop_all 0 do . loop ;
1 5 10 4 5
5 pop_all
But now I need to manually specify the stack size when I call it.
You can always find the number of items on the stack with the function DEPTH
. The value returned is the number of items on the stack before the number is returned.
大多数FORTH系统都有一个.S
命令,可以完全按照您的要求编写。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.