This commit is contained in:
Araq 2014-11-15 11:10:13 +01:00
commit f7dca91344
8 changed files with 31 additions and 10 deletions

View file

@ -84,7 +84,9 @@ current module:
var exportedVar*: int var exportedVar*: int
const exportedConst* = 78 const exportedConst* = 78
type ExportedType* = distinct int type
ExportedType* = object
exportedField*: int
Method call syntax Method call syntax
@ -107,6 +109,8 @@ to supply any type of first argument for procedures:
Another way to look at the method call syntax is that it provides the missing Another way to look at the method call syntax is that it provides the missing
postfix notation. postfix notation.
See also: `Limitations of the method call syntax`_.
Properties Properties
---------- ----------

View file

@ -225,8 +225,8 @@ a template. ``inject`` and ``gensym`` have no effect in ``dirty`` templates.
Limitations of the method invokation syntax Limitations of the method call syntax
------------------------------------------- -------------------------------------
The expression ``x`` in ``x.f`` needs to be semantically checked (that means The expression ``x`` in ``x.f`` needs to be semantically checked (that means
symbol lookup and type checking) before it can be decided that it needs to be symbol lookup and type checking) before it can be decided that it needs to be
@ -241,6 +241,21 @@ is used to invoke templates/macros:
unknownIdentifier.declareVar unknownIdentifier.declareVar
Another common example is this:
.. code-block:: nim
from sequtils import toSeq
iterator something: string =
yield "Hello"
yield "World"
var info = something().toSeq()
The problem here is that the compiler already decided that ``something()`` as
an iterator is not callable in this context before ``toSeq`` gets its
chance to convert it into a sequence.
Macros Macros
====== ======

View file

@ -302,6 +302,10 @@ template toSeq*(iter: expr): expr {.immediate.} =
## result = true) ## result = true)
## assert odd_numbers == @[1, 3, 5, 7, 9] ## assert odd_numbers == @[1, 3, 5, 7, 9]
## ##
## **Note**: Since this is an immediate macro, you cannot always invoke this
## as ``x.toSeq``, depending on the ``x``.
## See `this <manual.html#limitations-of-the-method-call-syntax>`_
## for an explanation.
var result {.gensym.}: seq[type(iter)] = @[] var result {.gensym.}: seq[type(iter)] = @[]
for x in iter: add(result, x) for x in iter: add(result, x)
result result

View file

@ -8,7 +8,7 @@
# #
## Floating-point environment. Handling of floating-point rounding and ## Floating-point environment. Handling of floating-point rounding and
## exceptions (overflow, zero-devide, etc.). ## exceptions (overflow, division by zero, etc.).
{.deadCodeElim:on.} {.deadCodeElim:on.}

View file

@ -904,9 +904,8 @@ proc `of` *[T, S](x: T, y: S): bool {.magic: "Of", noSideEffect.}
## Checks if `x` has a type of `y` ## Checks if `x` has a type of `y`
## ##
## .. code-block:: Nim ## .. code-block:: Nim
## assert(EFloatingPoint of EBase) ## assert(FloatingPointError of Exception)
## assert(EIO of ESystem) ## assert(DivByZeroError of Exception)
## assert(EDivByZero of EBase)
proc cmp*[T](x, y: T): int {.procvar.} = proc cmp*[T](x, y: T): int {.procvar.} =
## Generic compare proc. Returns a value < 0 iff x < y, a value > 0 iff x > y ## Generic compare proc. Returns a value < 0 iff x < y, a value > 0 iff x > y

View file

@ -1,7 +1,6 @@
version 0.10 version 0.10
============ ============
showstopper: Nim does not boot with --threads:on!
- make nimble part of the distribution - make nimble part of the distribution
- implement 'procCall' - implement 'procCall'
- split idetools into separate tool - split idetools into separate tool

View file

@ -40,7 +40,7 @@ Change the branch to suit your needs::
git clone -b master git://github.com/Araq/Nimrod.git git clone -b master git://github.com/Araq/Nimrod.git
cd Nimrod cd Nimrod
git clone --depth 1 git://github.com/nimrod-code/csources git clone -b master --depth 1 git://github.com/nimrod-code/csources
cd csources && sh build.sh cd csources && sh build.sh
cd .. cd ..
bin/nimrod c koch bin/nimrod c koch

View file

@ -67,7 +67,7 @@ News
----------------- -----------------
- Added module ``fenv`` to control the handling of floating-point rounding and - Added module ``fenv`` to control the handling of floating-point rounding and
exceptions (overflow, zero-devide, etc.). exceptions (overflow, division by zero, etc.).
2014-10-19 Nimrod version 0.9.6 released 2014-10-19 Nimrod version 0.9.6 released