diff options
author | Araq <rumpf_a@web.de> | 2011-06-19 17:45:33 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-06-19 17:45:33 +0200 |
commit | 8b6f9ef5e8c1203ab7d84a727523723c068475ed (patch) | |
tree | 8b4d04f7a14b25274ded06bdd4ffc7749335aa81 /doc | |
parent | 54021471e40d2cc2ff8f178192ba83873e7f43e0 (diff) | |
download | Nim-8b6f9ef5e8c1203ab7d84a727523723c068475ed.tar.gz |
case branches support constant sets for convenience
Diffstat (limited to 'doc')
-rwxr-xr-x | doc/manual.txt | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/doc/manual.txt b/doc/manual.txt index a284c6a0b..9b00233a1 100755 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -1527,6 +1527,27 @@ given, control passes after the ``case`` statement. To suppress the static error in the ordinal case an ``else`` part with a ``nil`` statement can be used. +As a special semantic extension, an expression in an ``of`` branch of a case +statement may evaluate to a set constructor; the set is then expanded into +a list of its elements: + +.. code-block:: nimrod + const + SymChars: set[char] = {'a'..'z', 'A'..'Z', '\x80'..'\xFF'} + + proc classify(s: string) = + case s[0] + of SymChars, '_': echo "an identifier" + of '0'..'9': echo "a number" + else: echo "other" + + # is equivalent to: + proc classify(s: string) = + case s[0] + of 'a'..'z', 'A'..'Z', '\x80'..'\xFF', '_': echo "an identifier" + of '0'..'9': echo "a number" + else: echo "other" + When statement ~~~~~~~~~~~~~~ |