summary refs log tree commit diff stats
path: root/doc
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-06-19 17:45:33 +0200
committerAraq <rumpf_a@web.de>2011-06-19 17:45:33 +0200
commit8b6f9ef5e8c1203ab7d84a727523723c068475ed (patch)
tree8b4d04f7a14b25274ded06bdd4ffc7749335aa81 /doc
parent54021471e40d2cc2ff8f178192ba83873e7f43e0 (diff)
downloadNim-8b6f9ef5e8c1203ab7d84a727523723c068475ed.tar.gz
case branches support constant sets for convenience
Diffstat (limited to 'doc')
-rwxr-xr-xdoc/manual.txt21
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

 ~~~~~~~~~~~~~~