Added [:T] syntax explanation to generics tutorial. (#15890)

* Added [:T] syntax explanation to generics tutorial.

* Update doc/tut2.rst

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>

* Update doc/tut2.rst

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>

* Made second generics example runnable and added test line.

* Update doc/tut2.rst

* Update doc/tut2.rst

* Update doc/tut2.rst

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
Aethylia
2020-11-09 13:14:06 +00:00
committed by GitHub
parent 3948b40bcd
commit 53eca459f1

View File

@@ -534,6 +534,19 @@ iterator or type. As the example shows, generics work with overloading: the
best match of ``add`` is used. The built-in ``add`` procedure for sequences
is not hidden and is used in the ``preorder`` iterator.
There is a special ``[:T]`` syntax when using generics with the method call syntax:
.. code-block:: nim
:test: "nim c $1"
proc foo[T](i: T) =
discard
var i: int
# i.foo[int]() # Error: expression 'foo(i)' has no type (or is ambiguous)
i.foo[:int]() # Success
Templates
=========