: ensure-depth \ n -- throws if n<depth

depth n:1- n:> if

"Stack not deep enough" throw

then ;

A common problem is unbalanced stacks. In particular, having a word which doesn't (always) obey its SED, or which does but whose SED is simply not correct in context.In such a case, it can happen that you expect, say, 2 items on the stack at a certain point in your code, but you've only got 1 or none. The following code-snippet can help you. Think of it as a stack-assert:You might enhance that by saying the stack must be exactly 3 deep, or not more than 10 deep or something (to catch badly-behaved words which leave more on the stack than they should).