+ documentation for implicit conversions
This commit is contained in:
parent
6850fb73c1
commit
00f0e9927f
2 changed files with 16 additions and 1 deletions
|
|
@ -1299,6 +1299,22 @@ algorithm returns true:
|
||||||
if b.kind == distinct and typeEquals(b.baseType, a): return true
|
if b.kind == distinct and typeEquals(b.baseType, a): return true
|
||||||
return false
|
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
|
Assignment compatibility
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -47,7 +47,6 @@ Low priority
|
||||||
is allocated
|
is allocated
|
||||||
- implicit conversions from ``ptr/ref T`` to ``var T`` (from
|
- implicit conversions from ``ptr/ref T`` to ``var T`` (from
|
||||||
``ptr/ref T`` to ``T``)?
|
``ptr/ref T`` to ``T``)?
|
||||||
- documentation: type converters
|
|
||||||
- typeAllowed() for parameters...
|
- typeAllowed() for parameters...
|
||||||
- find a way to reintroduce the cleanup() pass for C code generation: this
|
- 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
|
is hard because of partial evaluation --> symbol files will fix this as
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue