From 53eca459f1d96c710238be95bd3fb048b336f2f3 Mon Sep 17 00:00:00 2001 From: Aethylia Date: Mon, 9 Nov 2020 13:14:06 +0000 Subject: [PATCH] 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 --- doc/tut2.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/doc/tut2.rst b/doc/tut2.rst index 94725a5d82..32faf452c6 100644 --- a/doc/tut2.rst +++ b/doc/tut2.rst @@ -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 =========