> The documentation is pretty complete, there's just not much more to say.

In fact, perhaps I was only mislead as a non native English speaker by the fact 
that all examples in the [Templates 
section](https://nim-lang.org/docs/manual.html#templates) use `typed` and 
`untyped` parameters and thinking that only these types were available. I had 
to read again the documentation this morning to find the subtle nuance:

_The "types" of templates can be the symbols ``untyped``, ``typed`` or 
``typedesc``. These are "meta types", they can only be used in certain 
contexts._ **Regular types can be used too** ; _this implies that typed 
expressions are expected._

_Don 't know why the previous sentence can't be quoted in the forum..._

There's no explanations either that overloading applies to templates too and in 
that case `typed` and `untyped` meta types can conflict with regular types.

And yes, the documentation is complete. Perhaps we should have a reference to 
[Lazy type resolution for 
untyped](https://nim-lang.org/docs/manual.html#overloading-resolution-lazy-type-resolution-for-untyped)
 in the Templates and Macros sections.

Can you find what the following code will print? 
    
    
    template foo(x: int; y: string) =
      echo "foo1 " & $x & ", " & $y
    
    template foo(x: string; y: int) =
      echo "foo2 " & $x & ", " & $y
    
    template foo(x: typed; y: typed) =
      echo "foo3 " & $x & ", " & $y
    
    #template foo(x: untyped; y: untyped) =
    #  echo "foo4 " & $x & ", " & $y
    
    template foo(x: typed{lit}; y: typed) =
      echo "foo5 " & $x & ", " & $y
    
    template foo(x: typed{sym}; y: typed) =
      echo "foo6 " & $x & ", " & $y
    
    template foo(x: int; y: typed) =
      echo "foo7 " & $x & ", " & $y
    
    template foo(x: float; y: int; z: untyped = "No bar!") =
      echo "foo8 " & $x & ", " & $y & ", " & $z
    
    let x = 42
    let y = "bar"
    let z = 123.45
    
    foo(x, y)
    foo(y, x)
    foo(x, x)
    foo(y, y)
    foo(x, z)
    foo(-1, z)
    foo(3.14, y)
    foo(2.79, x)ΒΈ
    
    
    Run

Reply via email to