From 00f56b20d7e2edb903c7c486574ad793a078667a Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Tue, 5 Aug 2014 11:25:54 +0200 Subject: [PATCH 1/2] Adds usage example to typetraits.name(). Credit goes to fowl (http://forum.nimrod-lang.org/t/430). --- lib/pure/typetraits.nim | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim index e7bd363cf9..3203ee6997 100644 --- a/lib/pure/typetraits.nim +++ b/lib/pure/typetraits.nim @@ -11,7 +11,26 @@ ## working with types proc name*(t: typedesc): string {.magic: "TypeTrait".} - ## Returns the name of the given type + ## Returns the name of the given type. + ## + ## Example: + ## + ## .. code-block:: + ## + ## import typetraits + ## + ## proc `$`*[T](some:typedesc[T]): string = name(T) + ## + ## template test(x): stmt = + ## echo "type: ", type(x), ", value: ", x + ## + ## test 42 + ## # --> type: int, value: 42 + ## test "Foo" + ## # --> type: string, value: Foo + ## test(@['A','B']) + ## # --> type: seq[char], value: @[A, B] + proc arity*(t: typedesc): int {.magic: "TypeTrait".} - ## Returns the arity of the given type \ No newline at end of file + ## Returns the arity of the given type From 5c9d6762e48f0f5e70fed848ba11e79c86427206 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Tue, 5 Aug 2014 11:43:22 +0200 Subject: [PATCH 2/2] Adds typetraits to library index and doc build. --- doc/lib.txt | 5 ++++- web/nimrod.ini | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/lib.txt b/doc/lib.txt index 5bacfcc4f9..76e7354e01 100644 --- a/doc/lib.txt +++ b/doc/lib.txt @@ -56,7 +56,10 @@ Core * `typeinfo `_ Provides (unsafe) access to Nimrod's run time type information. - + +* `typetraits `_ + This module defines compile-time reflection procs for working with types. + * `actors `_ Actor support for Nimrod; implemented as a layer on top of the threads and channels modules. diff --git a/web/nimrod.ini b/web/nimrod.ini index 544446b11e..38a906ac57 100644 --- a/web/nimrod.ini +++ b/web/nimrod.ini @@ -41,7 +41,7 @@ doc: "tools;niminst;nimgrep;gc;estp;idetools;docgen;koch;backends.txt" pdf: "manual;lib;tut1;tut2;nimrodc;niminst;gc" srcdoc2: "system.nim;impure/graphics;wrappers/sdl" srcdoc2: "core/macros;pure/marshal;core/typeinfo;core/unsigned" -srcdoc2: "impure/re;pure/sockets" +srcdoc2: "impure/re;pure/sockets;pure/typetraits" srcdoc: "system/threads.nim;system/channels.nim;js/dom" srcdoc2: "pure/os;pure/strutils;pure/math;pure/matchers;pure/algorithm" srcdoc2: "pure/complex;pure/times;pure/osproc;pure/pegs;pure/dynlib"