Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added documentation for implicit conversions #22

Merged
merged 1 commit into from
Mar 24, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 0 additions & 1 deletion todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down