diff options
Diffstat (limited to 'doc')
-rw-r--r-- | doc/manual/generics.txt | 11 | ||||
-rw-r--r-- | doc/manual/pragmas.txt | 15 | ||||
-rw-r--r-- | doc/manual/types.txt | 24 |
3 files changed, 39 insertions, 11 deletions
diff --git a/doc/manual/generics.txt b/doc/manual/generics.txt index 8f7dcd580..c6206d030 100644 --- a/doc/manual/generics.txt +++ b/doc/manual/generics.txt @@ -116,7 +116,7 @@ type class matches ``array`` any array type ``set`` any set type ``seq`` any seq type -``auto`` any type +``any`` any type ================== =================================================== Furthermore, every generic type automatically creates a type class of the same @@ -163,15 +163,6 @@ module to illustrate this: Alternatively, the ``distinct`` type modifier can be applied to the type class to allow each param matching the type class to bind to a different type. -If a proc param doesn't have a type specified, Nim will use the -``distinct auto`` type class (also known as ``any``). Note this behavior is -deprecated for procs; templates, however, support them: - -.. code-block:: nim - # allow any combination of param types - proc concat(a, b): string = $a & $b # deprecated - proc concat(a, b: any): string = $a & $b # preferred - Procs written with the implicitly generic style will often need to refer to the type parameters of the matched generic type. They can be easily accessed using the dot syntax: diff --git a/doc/manual/pragmas.txt b/doc/manual/pragmas.txt index 8166994a9..68a88f865 100644 --- a/doc/manual/pragmas.txt +++ b/doc/manual/pragmas.txt @@ -72,7 +72,20 @@ compileTime pragma ------------------ The ``compileTime`` pragma is used to mark a proc or variable to be used at compile time only. No code will be generated for it. Compile time procs are -useful as helpers for macros. +useful as helpers for macros. Since version 0.12.0 of the language, a proc +that uses ``system.NimNode`` within its parameter types is implictly declared +``compileTime``: + +.. code-block:: nim + proc astHelper(n: NimNode): NimNode = + result = n + +Is the same as: + +.. code-block:: nim + proc astHelper(n: NimNode): NimNode {.compileTime.} = + result = n + noReturn pragma --------------- diff --git a/doc/manual/types.txt b/doc/manual/types.txt index 44a20d093..c9ac6f062 100644 --- a/doc/manual/types.txt +++ b/doc/manual/types.txt @@ -1228,3 +1228,27 @@ However, a ``void`` type cannot be inferred in generic code: The ``void`` type is only valid for parameters and return types; other symbols cannot have the type ``void``. + + +Auto type +--------- + +The ``auto`` type can only be used for return types and parameters. For return +types it causes the compiler to infer the type from the routine body: + +.. code-block:: nim + proc returnsInt(): auto = 1984 + +For parameters it currently creates implicitly generic routines: + +.. code-block:: nim + proc foo(a, b: auto) = discard + +Is the same as: + +.. code-block:: nim + proc foo[T1, T2](a: T1, b: T2) = discard + +However later versions of the language might change this to mean "infer the +parameters' types from the body". Then the above ``foo`` would be rejected as +the parameters' types can not be infered from an empty ``discard`` statement. |