Change to hard word wrap at 80.

This commit is contained in:
Oscar Campbell
2015-05-25 06:00:37 +02:00
parent feff2bae68
commit 625299e861
4 changed files with 33 additions and 17 deletions

View File

@@ -2,13 +2,14 @@ About this document
===================
**Note**: This document is a draft! Several of Nim's features may need more
precise wording. This manual is constantly evolving until the 1.0 release and is not to be considered as the final proper specification.
precise wording. This manual is constantly evolving until the 1.0 release and is
not to be considered as the final proper specification.
This document describes the lexis, the syntax, and the semantics of Nim.
The language constructs are explained using an extended BNF, in
which ``(a)*`` means 0 or more ``a``'s, ``a+`` means 1 or more ``a``'s, and
``(a)?`` means an optional *a*. Parentheses may be used to group elements.
The language constructs are explained using an extended BNF, in which ``(a)*``
means 0 or more ``a``'s, ``a+`` means 1 or more ``a``'s, and ``(a)?`` means an
optional *a*. Parentheses may be used to group elements.
``&`` is the lookahead operator; ``&a`` means that an ``a`` is expected but
not consumed. It will be consumed in the following rule.

View File

@@ -26,7 +26,8 @@ It can also be used as a statement, in that case it takes a list of *renamings*.
Stream = ref object
{.deprecated: [TFile: File, PStream: Stream].}
The ``nimfix`` tool can be used to, without effort, automatically update your code and refactor it by performing these renamings.
The ``nimfix`` tool can be used to, without effort, automatically update your
code and refactor it by performing these renamings.
noSideEffect pragma
@@ -430,7 +431,10 @@ Example:
of the symbols may include other call expressions, whose types will be resolved
at this point too.
3. Finally, after the best overload is picked, the compiler will start compiling the body of the respective symbol. This in turn will lead the compiler to discover more call expressions that need to be resolved and steps 2 and 3 will be repeated as necessary.
3. Finally, after the best overload is picked, the compiler will start
compiling the body of the respective symbol. This in turn will lead the
compiler to discover more call expressions that need to be resolved and steps
2 and 3 will be repeated as necessary.
Please note that if a callable symbol is never used in this scenario, its body
will never be compiled. This is the default behavior leading to best compilation

View File

@@ -2,9 +2,14 @@ Procedures
==========
What most programming languages call `methods`:idx: or `functions`:idx: are
called `procedures`:idx: in Nim (which is the correct terminology). A
procedure declaration consists of an identifier, zero or more formal parameters, a return value type and a block of code.
Formal parameters are declared as a list of identifiers separated by either comma or semicolon. A parameter is given a type by ``: typename``. The type applies to all parameters immediately before it, until either the beginning of the parameter list, a semicolon separator or an already typed parameter, is reached. The semicolon can be used to make separation of types and subsequent identifiers more distinct.
called `procedures`:idx: in Nim (which is the correct terminology). A procedure
declaration consists of an identifier, zero or more formal parameters, a return
value type and a block of code. Formal parameters are declared as a list of
identifiers separated by either comma or semicolon. A parameter is given a type
by ``: typename``. The type applies to all parameters immediately before it,
until either the beginning of the parameter list, a semicolon separator or an
already typed parameter, is reached. The semicolon can be used to make
separation of types and subsequent identifiers more distinct.
.. code-block:: nim
# Using only commas
@@ -16,23 +21,26 @@ Formal parameters are declared as a list of identifiers separated by either comm
# Will fail: a is untyped since ';' stops type propagation.
proc foo(a; b: int; c, d: bool): int
A parameter may be declared with a default value which is used if the caller does not provide a value for the argument.
A parameter may be declared with a default value which is used if the caller
does not provide a value for the argument.
.. code-block:: nim
# b is optional, 47 is its default value
proc foo(a, b: int = 47): int
Parameters can be declared mutable and so allow the proc to modify those arguments, by using the type modifier `var`.
Parameters can be declared mutable and so allow the proc to modify those
arguments, by using the type modifier `var`.
.. code-block:: nim
# "returning" a value to the caller through the 2nd argument
proc foo(inp: int, outp: var int): void =
outp = inp + 47
If the proc declaration has no body, it is a `forward`:idx: declaration. If
the proc returns a value, the procedure body can access an implicitly declared
If the proc declaration has no body, it is a `forward`:idx: declaration. If the
proc returns a value, the procedure body can access an implicitly declared
variable named `result`:idx: that represents the return value. Procs can be
overloaded. The overloading resolution algorithm determines which proc is the best match for the arguments. Example:
overloaded. The overloading resolution algorithm determines which proc is the
best match for the arguments. Example:
.. code-block:: nim
@@ -530,7 +538,8 @@ Closure iterators have other restrictions than inline iterators:
1. ``yield`` in a closure iterator can not occur in a ``try`` statement.
2. For now, a closure iterator cannot be evaluated at compile time.
3. ``return`` is allowed in a closure iterator (but rarely useful) and ends iteration..
3. ``return`` is allowed in a closure iterator (but rarely useful) and ends
iteration..
4. Neither inline nor closure iterators can be recursive.
Iterators that are neither marked ``{.closure.}`` nor ``{.inline.}`` explicitly

View File

@@ -43,7 +43,8 @@ Fortunately Nim supports side effect analysis:
echo f() * 2 # not optimized ;-)
You can make one overload for constrained match and without, and the constrained will be prioritized, and so you can handle both cases differently.
You can make one overload for constrained match and without, and the constrained
will be prioritized, and so you can handle both cases differently.
So what about ``2 * a``? We should tell the compiler ``*`` is commutative. We
cannot really do that however as the following code only swaps arguments
@@ -107,10 +108,11 @@ Predicate Meaning
with the marked parameter.
=================== =====================================================
Predicates that share their name with a keyword have to be escaped with
backticks: `` `const` ``.
The ``alias`` and ``noalias`` predicates refer not only to the matching AST,
but also to every other bound parameter; syntactically they need to occur after
the ordinary AST predicates:
Predicates that share their name with a keyword have to be escaped with backticks: `` `const` ``.
.. code-block:: nim
template ex{a = b + c}(a: int{noalias}, b, c: int) =