Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current stack size in FORTH

Tags:

stack

forth

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.

like image 417
sashoalm Avatar asked Sep 03 '13 13:09

sashoalm


1 Answers

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.

like image 105
Leo Chapiro Avatar answered Sep 21 '22 14:09

Leo Chapiro