You are welcome.

Plus another side note: Nim templates _are_ (what C calls) macros albeit pimped 
up and cleaner. One important point to remember is that templates (unlike Nim 
macros) are basically but smart text substitution. This also means that any 
variables one refers to must either be defined in the _calling_ context or be 
provided as parameters. And it means that a template "returning" something 
(like `let x = mytemplate(...)` can be looked at (in the _" caller"_ as 
basically just "do everything but last template expression ... and then assign 
last expression to x".

So in my code above, if push and pop and "called" in, say, proc foo the 
following happens:
    
    
    template push(val: int) =
       stack[p] = val
       p.inc()
    
    template pop(): int =
       p.dec()
       stack[p]
       
       push(bar)
       # ... some other stuff
       let r = pop()
    
    Run

comes down to
    
    
    proc foo(...) =
       var stack = array[10, int]
       var p = 0
       var bar = 5
       # push(bar)
       stack[p] = bar
       p.inc()
       # ... some other stuff
       # let r = pop()
       p.dec()
       let r = stack[p]
    
    Run

Reply via email to