diff options
author | Araq <rumpf_a@web.de> | 2012-11-08 08:32:08 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-11-08 08:32:08 +0100 |
commit | ed28f3c8dc342e1b057c3df62ad7da371444891e (patch) | |
tree | 155179dacb82ef85e5033de3d90e2a5ac836ed17 /doc | |
parent | 515cf985f41dcce7751018ee678109b17b886643 (diff) | |
download | Nim-ed28f3c8dc342e1b057c3df62ad7da371444891e.tar.gz |
documented 'mixin' declaration
Diffstat (limited to 'doc')
-rwxr-xr-x | doc/manual.txt | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/doc/manual.txt b/doc/manual.txt index 59ef5850a..414c43874 100755 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -2778,7 +2778,12 @@ This allows for a Lisp-like `condition system`:idx:\: var myFile = open("broken.txt", fmWrite) try: onRaise(proc (e: ref E_Base): bool = - stdout.writeln "ok, writing to stdout instead") + if e of EIO: + stdout.writeln "ok, writing to stdout instead" + else: + # do raise other exceptions: + result = true + ) myFile.writeln "writing to broken file" finally: myFile.close() @@ -2859,6 +2864,9 @@ effect is a means to *tag* a routine and perform checks against this tag: # the compiler prevents this: let x = readLine() +A tag has to be a type name. A ``tags`` list - like a ``raises`` list - can +also be attached to a proc type. This affects type compatibility. + The inference for tag tracking is analogous to the inference for exception tracking. @@ -2948,6 +2956,7 @@ Example: `type parameters`:idx:. Depending on context, the brackets are used either to introduce type parameters or to instantiate a generic proc, iterator or type. + Is operator ~~~~~~~~~~~ @@ -3084,6 +3093,8 @@ To be written. Return Type Inference ~~~~~~~~~~~~~~~~~~~~~ +**Note**: ``auto`` is not yet implemented. + If a type class is used as the return type of a proc and it won't be bound to a concrete type by some of the proc params, Nimrod will infer the return type from the proc body. This is usually used with the ``auto`` type class: @@ -3098,12 +3109,17 @@ Future versions of nimrod may also support overloading based on the return type of the overloads. In such settings, the expected result type at call sites may also influence the inferred return type. + Symbol lookup in generics ~~~~~~~~~~~~~~~~~~~~~~~~~ -Symbols in generics are looked up in two different contexts: Both the context -at definition and the context at instantiation are considered for any symbol -occurring in a generic: +The symbol binding rules in generics are slightly subtle: There are "open" and +"closed" symbols. A "closed" symbol cannot be re-bound in the instantiation +context, an "open" symbol can be. Per default overloaded symbols are open +and every other symbol is closed. + +Open symbols are looked up in two different contexts: Both the context +at definition and the context at instantiation are considered: .. code-block:: nimrod type @@ -3122,6 +3138,16 @@ the ``TIndex`` type is defined *after* the ``==`` for tuples; yet the example compiles as the instantiation takes the currently defined symbols into account too. +A symbol can be forced to be open by a `mixin`:idx: declaration: + +.. code-block:: nimrod + proc create*[T](): ref T = + # there is no overloaded 'mixin' here, so we need to state that it's an + # open symbol explicitly: + mixin init + new result + init result + Templates --------- |