This should do what you want:
    
    
    template push(val: int) =
       stack[p] = val
       p.inc()
    
    template pop(): int =
       p.dec()
       stack[p]
    
    Run

The relevant point isn't the stack logic (p++ vs p--) but that a template that 
is supposed to "return" something is supposed to have that something - in this 
case `stack[p]` \- as _last_ expression. So in your pop() version the template 
were to "return" the decremented `p` (if it could).

You could make it work however if you changed it to:
    
    
    template POP =
      let v = stack[p]; dec p; v
    
    Run

Side note: in Nim identifiers that start with a capital letter are supposed to 
be types, so "PUSH" and "POP" while being typical for C are a poor choice in 
Nim.

Reply via email to