summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSimon Hafner <hafnersimon@gmail.com>2011-03-18 23:52:44 +0100
committerSimon Hafner <hafnersimon@gmail.com>2011-03-18 23:52:44 +0100
commit00f0e9927fad0b941e4f98d18f49a3be8373b5c6 (patch)
treee4d6ee51a789dd0938fac8d5e2c61f7933e76ee2
parent6850fb73c1b9ae8d3f56a61ee37922c3cb3788d6 (diff)
downloadNim-00f0e9927fad0b941e4f98d18f49a3be8373b5c6.tar.gz
+ documentation for implicit conversions
-rwxr-xr-xdoc/manual.txt16
-rwxr-xr-xtodo.txt1
2 files changed, 16 insertions, 1 deletions
diff --git a/doc/manual.txt b/doc/manual.txt
index 49311fb43..3ee02aaa4 100755
--- a/doc/manual.txt
+++ b/doc/manual.txt
@@ -1299,6 +1299,22 @@ algorithm returns true:
     if b.kind == distinct and typeEquals(b.baseType, a): return true

     return false

     

+You can, however, define your own implicit converters:

+

+.. code-block:: nimrod

+  converter toInt(x: char): int = result = ord(x)

+

+  var

+    x: int

+    chr: char = 'a'

+

+  # implicit conversion magic happens here

+  x = chr

+  echo x # => 97

+  # you can use the explicit form too

+  x = chr.toInt

+  echo x # => 97

+

 

 Assignment compatibility

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

diff --git a/todo.txt b/todo.txt
index 5fa136e1f..46b037d34 100755
--- a/todo.txt
+++ b/todo.txt
@@ -47,7 +47,6 @@ Low priority
   is allocated
 - implicit conversions from ``ptr/ref T`` to ``var T`` (from
   ``ptr/ref T`` to ``T``)?
-- documentation: type converters
 - typeAllowed() for parameters...
 - find a way to reintroduce the cleanup() pass for C code generation: this
   is hard because of partial evaluation --> symbol files will fix this as