diff options
author | Araq <rumpf_a@web.de> | 2011-04-23 17:11:24 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-04-23 17:11:24 +0200 |
commit | 4ba4999bb7b172b683cf7b8d574adbf04afa7527 (patch) | |
tree | f1216df68dba7abb0e9324afa11464db885800dd /doc/manual.txt | |
parent | 05fee773ec48b5b45cdb7469a6c8410b59fcb542 (diff) | |
download | Nim-4ba4999bb7b172b683cf7b8d574adbf04afa7527.tar.gz |
slice support in system.nim; syntactic sugar for tables; cleanup of grammar/parser
Diffstat (limited to 'doc/manual.txt')
-rwxr-xr-x | doc/manual.txt | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/doc/manual.txt b/doc/manual.txt index e230861fb..9067946ac 100755 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -1815,6 +1815,34 @@ Example: An if expression always results in a value, so the ``else`` part is required. ``Elif`` parts are also allowed (but unlikely to be good style). + + +Table constructor +~~~~~~~~~~~~~~~~~ + +A `table constructor`:idx: is syntactic sugar for an array constructor: + +.. code-block:: nimrod + {"key1": "value1", "key2": "value2"} + + # is the same as: + [("key1", "value1"), ("key2", "value2")] + + +The empty table can be written ``{:}`` (in contrast to the empty set +which is ``{}``) which is thus another way to write as the empty array +constructor ``[]``. This slightly unusal way of supporting tables +has lots of advantages: + +* The order of the (key,value)-pairs is preserved, thus it is easy to + support ordered dicts with for example ``{key: val}.newOrderedTable``. +* A table literal can be put into a ``const`` section and the compiler + can easily put it into the executable's data section just like it can + for arrays and the generated data section requires a minimal amount + of memory. +* Every table implementation is treated equal syntactically. +* Apart from the minimal syntactic sugar the language core does not need to + know about tables. Type conversions |