According this in [Nim 
tutorial](https://nim-lang.org/docs/tut1.html#procedures-parameters):

> Parameters are immutable in the procedure body. By default, their value 
> cannot be changed because this allows the compiler to implement parameter 
> passing in the most efficient way. If a mutable variable is needed inside the 
> procedure, it has to be declared with `var` in the procedure body. Shadowing 
> the parameter name is possible, and actually an idiom:
>     
>     
>     proc printSeq(s: seq, nprinted: int = -1) =
>       var nprinted = if nprinted == -1: s.len else: min(nprinted, s.len)
>       for i in 0 ..< nprinted:
>         echo s[i]
>     
>     
>     Run

I tested this example, but changed `var` to `let`. My code:
    
    
    proc printSeq(s: seq, nprinted: int = -1) =
        let nprinted = if nprinted == -1 : s.len else: min(nprinted, s.len)
        for i in 0 ..< nprinted:
            echo s[i]
    
    printSeq(@['a', 'b', 'c', 'd', 'e', 'f'])
    
    
    Run

My code works fine:

(how to insert screenshot?)

So can I use `let`? Is document is correct there? Or it's a bit old?

Orlean.

Reply via email to