Get current stack size in FORTH

How to get the number of items on the stack in Forth?

I ask about this because I want to create a function that displays all the elements of the stack, for example:

: pop_all 0 do . loop ; 1 5 10 4 5 5 pop_all 

But now I need to manually specify the size of the stack when I call it.

+6
source share
1 answer

You can always find the number of items on the stack using the DEPTH function. Return value - the number of elements on the stack before the number is returned.

+7
source

Source: https://habr.com/ru/post/953061/


All Articles