docs: fix some spelling errors (#19816)

* docs: fix some spelling errors

* contributing: fix spelling error

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

* Update contributing.md

* Update intern.md

* Update manual.md

* Update manual_experimental_strictnotnil.md

* Update nimgrep_cmdline.txt

* Update pegdocs.txt

* Update testament.md

* Update tut1.md

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
This commit is contained in:
ee7
2022-08-09 20:01:46 +02:00
committed by GitHub
parent e8ae2dc90b
commit b4157f6772
10 changed files with 143 additions and 141 deletions

View File

@@ -8,7 +8,7 @@ Contributing
.. contents::
Contributing happens via "Pull requests" (PR) on github. Every PR needs to be
Contributing happens via "Pull requests" (PR) on GitHub. Every PR needs to be
reviewed before it can be merged and the Continuous Integration should be green.
The title of a PR should contain a brief description. If it fixes an issue,
in addition to the number of the issue, the title should also contain a description
@@ -158,7 +158,7 @@ To run a single test:
```
For reproducible tests (to reproduce an environment more similar to the one
run by Continuous Integration on github actions/azure pipelines), you may want to disable your
run by Continuous Integration on GitHub actions/azure pipelines), you may want to disable your
local configuration (e.g. in ``~/.config/nim/nim.cfg``) which may affect some
tests; this can also be achieved by using
`export XDG_CONFIG_HOME=pathtoAlternateConfig`:cmd: before running `./koch`:cmd:
@@ -198,8 +198,8 @@ tell you if any new tests passed/failed.
Deprecation
===========
Backward compatibility is important, so instead of a rename you need to deprecate
the old name and introduce a new name:
Backwards compatibility is important. When renaming types, procedures, etc. the old name
must be marked as deprecated using the `deprecated` pragma:
```nim
# for routines (proc/template/macro/iterator) and types:
@@ -310,7 +310,7 @@ Inline monospaced text can be input using \`single backticks\` or
the latter are not.
To avoid accidental highlighting follow this rule in ``*.nim`` files:
* use single backticks for fragments of code in Nim and other
* Use single backticks for fragments of code in Nim and other
programming languages, including identifiers, in ``*.nim`` files.
For languages other than Nim add a role after final backtick,
@@ -326,12 +326,12 @@ To avoid accidental highlighting follow this rule in ``*.nim`` files:
Highlight shell commands by ``:cmd:`` role; for command line options use
``:option:`` role, e.g.: \`--docInternal\`:option:.
* prefer double backticks otherwise:
* Use double backticks:
* for file names: \`\`os.nim\`\`
* for fragments of strings **not** enclosed by `"` and `"` and not
* For file names: \`\`os.nim\`\`
* For fragments of strings **not** enclosed by `"` and `"` and not
related to code, e.g. text of compiler messages
* also when code ends with a standalone ``\`` (otherwise a combination of
* When code ends with a standalone ``\`` (otherwise a combination of
``\`` and a final \` would get escaped)
.. Note:: ``*.rst`` files have ``:literal:`` as their default role.
@@ -396,7 +396,7 @@ rationale: https://forum.nim-lang.org/t/4089
.. _tests_use_doAssert:
Use `doAssert` (or `unittest.check`, `unittest.require`), not `assert` in all
tests so they'll be enabled even with `--assertions:off`:option:.
tests, so they'll be enabled even with `--assertions:off`:option:.
```nim
block: # foo
@@ -423,7 +423,7 @@ second example below:
.. _delegate_printing:
Delegate printing to caller: return `string` instead of calling `echo`
rationale: it's more flexible (e.g. allows the caller to call custom printing,
including prepending location info, writing to log files, etc).
including prepending location info, writing to log files, etc.).
```nim
proc foo() = echo "bar" # bad
@@ -476,7 +476,7 @@ General commit rules
your editor reformatted automatically the code or whatever different reason,
this should be excluded from the commit.
*Tip:* Never commit everything as is using `git commit -a`:cmd:, but review
*Tip:* Never commit everything as-is using `git commit -a`:cmd:, but review
carefully your changes with `git add -p`:cmd:.
4. Changes should not introduce any trailing whitespace.
@@ -494,16 +494,16 @@ General commit rules
Fixes #123; refs #124
indicates that issue ``#123`` is completely fixed (GitHub may automatically
close it when the PR is committed), wheres issue ``#124`` is referenced
close it when the PR is committed), whereas issue ``#124`` is referenced
(e.g.: partially fixed) and won't close the issue when committed.
6. PR body (not just PR title) should contain references to fixed/referenced github
issues, e.g.: ``fix #123`` or ``refs #123``. This is so that you get proper cross
referencing from linked issue to the PR (github won't make those links with just
PR title, and commit messages aren't always sufficient to ensure that, e.g.
can't be changed after a PR is merged).
6. PR body (not just PR title) should contain references to fixed/referenced GitHub
issues, e.g.: ``fix #123`` or ``refs #123``. This is so that you get proper
cross-referencing from linked issue to the PR (GitHub won't make those links
with just a PR title, and commit messages aren't always sufficient to ensure
that, e.g. can't be changed after a PR is merged).
7. Commits should be always be rebased against devel (so a fast forward
7. Commits should be always be rebased against devel (so a fast-forward
merge can happen)
e.g.: use `git pull --rebase origin devel`:cmd:. This is to avoid messing up
@@ -523,14 +523,14 @@ Continuous Integration (CI)
1. Continuous Integration is by default run on every push in a PR; this clogs
the CI pipeline and affects other PR's; if you don't need it (e.g. for WIP or
documentation only changes), add ``[skip ci]`` to your commit message title.
This convention is supported by our github actions pipelines and our azure pipeline
This convention is supported by our GitHub actions pipelines and our azure pipeline
(using custom logic, which should complete in < 1mn) as well as our former other pipelines:
`Appveyor <https://www.appveyor.com/docs/how-to/filtering-commits/#skip-directive-in-commit-message>`_
and `Travis <https://docs.travis-ci.com/user/customizing-the-build/#skipping-a-build>`_.
2. Consider enabling CI (azure, GitHub actions and builds.sr.ht) in your own Nim fork, and
waiting for CI to be green in that fork (fixing bugs as needed) before
opening your PR in the original Nim repo, so as to reduce CI congestion. Same
opening your PR in the original Nim repo, to reduce CI congestion. Same
applies for updates on a PR: you can test commits on a separate private
branch before updating the main PR.
@@ -547,11 +547,12 @@ Debugging CI failures, flaky tests, etc
follow these instructions to only restart the jobs that failed:
* Azure: if on your own fork, it's possible from inside azure console
(e.g. ``dev.azure.com/username/username/_build/results?buildId=1430&view=results``) via ``rerun failed jobs`` on top.
(e.g. ``dev.azure.com/username/username/_build/results?buildId=1430&view=results``) via
``rerun failed jobs`` on top.
If either on you own fork or in Nim repo, it's possible from inside GitHub UI
under checks tab, see https://github.com/timotheecour/Nim/issues/211#issuecomment-629751569
* GitHub actions: under "Checks" tab, click "Re-run jobs" in the right.
* builds.sr.ht: create a sourcehut account so you can restart a PR job as illustrated.
* builds.sr.ht: create a SourceHut account so that you can restart a PR job as illustrated.
builds.sr.ht also allows you to ssh to a CI machine which can help a lot for debugging
issues, see docs in https://man.sr.ht/builds.sr.ht/build-ssh.md and
https://drewdevault.com/2019/08/19/Introducing-shell-access-for-builds.html; see
@@ -566,7 +567,7 @@ Code reviews
https://forum.nim-lang.org/t/4317
2. When reviewing large diffs that may involve code moving around, GitHub's interface
doesn't help much as it doesn't highlight moves. Instead, you can use something
doesn't help much, as it doesn't highlight moves. Instead, you can use something
like this, see visual results `here <https://github.com/nim-lang/Nim/pull/10431#issuecomment-456968196>`_:
```cmd
@@ -619,7 +620,7 @@ Time handling, especially the `Time` type are also covered by this rule.
Existing, battle-tested modules stay
------------------------------------
Reason: There is no benefit in moving them around just to fullfill some design
Reason: There is no benefit in moving them around just to fulfill some design
fashion as in "Nim's core MUST BE SMALL". If you don't like an existing module,
don't import it. If a compilation target (e.g. JS) cannot support a module,
document this limitation.
@@ -633,7 +634,7 @@ Syntactic helpers can start as experimental stdlib modules
Reason: Generally speaking as external dependencies they are not exposed
to enough users so that we can see if the shortcuts provide enough benefit
or not. Many programmers avoid external dependencies, even moreso for
or not. Many programmers avoid external dependencies, especially for
"tiny syntactic improvements". However, this is only true for really good
syntactic improvements that have the potential to clean up other parts of
the Nim library substantially. If in doubt, new stdlib modules should start
@@ -658,7 +659,7 @@ to existing modules is acceptable. For two reasons:
("Why does sequtils lack a `countIt`?
Because version 1.0 happens to have lacked it? Silly...")
2. To encourage contributions. Contributors often start with PRs that
add simple things and then they stay and also fix bugs. Nim is an
add simple things, then they stay and also fix bugs. Nim is an
open source project and lives from people's contributions and involvement.
Newly introduced issues have to be balanced against motivating new people. We know where
to find perfectly designed pieces of software that have no bugs -- these are the systems
@@ -684,7 +685,7 @@ Conventions
Breaking Changes
================
Introducing breaking changes, no matter how well intentioned,
Introducing breaking changes, no matter how well-intentioned,
creates long-term problems for the community, in particular those looking to promote
reusable Nim code in libraries: In the Nim distribution, critical security and bugfixes,
language changes and community improvements are bundled in a single distribution - it is
@@ -719,14 +720,14 @@ Examples of run-time breaking changes:
* "Nim's path handling procs like `getXDir` now consistently lack the trailing slash"
* "Nim's strformat implementation is now more consistent with Python"
Instead write new code that explicitly announces the feature you think we announced but
Instead, write new code that explicitly announces the feature you think we announced but
didn't. For example, `strformat` does not say "it's compatible with Python", it
says "inspired by Python's f-strings". This new code can be submitted to the stdlib
and the old code can be deprecated or it can be published as a Nimble package.
and the old code can be deprecated or published as a Nimble package.
Sometimes, a run-time breaking change is most desirable: For example, a string
representation of a floating point number that "roundtrips" is much better than
a string represenation that doesn't. These run-time breaking changes must start in the
a string representation that doesn't. These run-time breaking changes must start in the
state "opt-in" via a new `-d:nimPreviewX` or command line flag and then should become
the new default later, in follow-up versions. This way users can track
regressions more easily. ("git bisect" is not an acceptable alternative, that's for
@@ -740,7 +741,8 @@ Compile-time breaking changes
-----------------------------
Compile-time breaking changes are usually easier to handle, but for large code bases
it can also be much work and it can hinder the adoption of a new Nim release.
they can also involve a large amount of work and can hinder the adoption of a new
Nim release.
Additive approaches are to be preferred here as well.
Examples of compile-time breaking changes include (but are not limited to):
@@ -748,10 +750,10 @@ Examples of compile-time breaking changes include (but are not limited to):
* Renaming functions and modules, or moving things. Instead of a direct rename,
deprecate the old name and introduce a new one.
* Renaming the parameter names: Thanks to Nim's "named parameter" calling syntax
like `f(x = 0, y = 1)` this is a breaking change. Instead live with the existing
like `f(x = 0, y = 1)` this is a breaking change. Instead, live with the existing
parameter names.
* Adding an enum value to an existing enum. Nim's exhaustive case statements stop
compiling after such a change. Instead consider to introduce new `bool`
compiling after such a change. Instead, consider to introduce new `bool`
fields/parameters. This can be impractical though, so we use good judgement
and our list of "important packages" to see if it doesn't break too much code
out there in practice.

View File

@@ -11,7 +11,7 @@ Iff a proc is side effect free and all its argument are evaluable at
compile time, it can be evaluated by the compiler. However, really
difficult is the ``newString`` proc: If it is simply wrapped, it
should not be evaluated at compile time! On other occasions it can
and should be evaluted:
and should be evaluated:
.. code-block:: nim
proc toUpper(s: string): string =

View File

@@ -87,7 +87,7 @@ Bisecting for regressions
-------------------------
There are often times when there is a bug that is caused by a regression in the
compiler or stdlib. Bisecting the Nim repo commits is a usefull tool to identify
compiler or stdlib. Bisecting the Nim repo commits is a useful tool to identify
what commit introduced the regression.
Even if it's not known whether a bug is caused by a regression, bisection can reduce
@@ -117,7 +117,7 @@ fastest to build a compiler that is instrumented for debugging from an
existing release build. `koch temp`:cmd: provides a convenient method of doing
just that.
By default running `koch temp`:cmd: will build a lean version of the compiler
By default, running `koch temp`:cmd: will build a lean version of the compiler
with `-d:debug`:option: enabled. The compiler is written to `bin/nim_temp` by
default. A lean version of the compiler lacks JS and documentation generation.
@@ -125,7 +125,7 @@ default. A lean version of the compiler lacks JS and documentation generation.
with `testament --nim:bin/nim_temp r tests/category/tsometest`:cmd:.
`koch temp`:cmd: will build the temporary compiler with the `-d:debug`:option:
enabled. Here are compiler options that are of interest for debugging:
enabled. Here are compiler options that are of interest when debugging:
* `-d:debug`:option:\: enables `assert` statements and stacktraces and all
runtime checks
@@ -156,11 +156,11 @@ Debug logging
"Printf debugging" is still the most appropriate way to debug many problems
arising in compiler development. The typical usage of breakpoints to debug
the code is often less practical, because almost all of the code paths in the
the code is often less practical, because almost all code paths in the
compiler will be executed hundreds of times before a particular section of the
tested program is reached where the newly developed code must be activated.
To work-around this problem, you'll typically introduce an if statement in the
To work around this problem, you'll typically introduce an if statement in the
compiler code detecting more precisely the conditions where the tested feature
is being used. One very common way to achieve this is to use the `mdbg` condition,
which will be true only in contexts, processing expressions and statements from
@@ -374,7 +374,7 @@ Files that may need changed for your platform include:
Add os/cpu compiler/linker flags.
If the `--os` or `--cpu` options aren't passed to the compiler, then Nim will
determine the current host os, cpu and endianess from `system.cpuEndian`,
determine the current host os, cpu and endianness from `system.cpuEndian`,
`system.hostOS` and `system.hostCPU`. Those values are derived from
`compiler/platform.nim`.
@@ -398,17 +398,17 @@ Runtime type information
programming language:
Garbage collection
The old GCs use the RTTI for traversing abitrary Nim types, but usually
The old GCs use the RTTI for traversing arbitrary Nim types, but usually
only the `marker` field which contains a proc that does the traversal.
Complex assignments
Sequences and strings are implemented as
pointers to resizeable buffers, but Nim requires copying for
pointers to resizable buffers, but Nim requires copying for
assignments. Apart from RTTI the compiler also generates copy procedures
as a specialization.
We already know the type information as a graph in the compiler.
Thus we need to serialize this graph as RTTI for C code generation.
Thus, we need to serialize this graph as RTTI for C code generation.
Look at the file ``lib/system/hti.nim`` for more information.
@@ -418,7 +418,7 @@ Magics and compilerProcs
The `system` module contains the part of the RTL which needs support by
compiler magic. The C code generator generates the C code for it, just like any other
module. However, calls to some procedures like `addInt` are inserted by
the generator. Therefore there is a table (`compilerprocs`)
the generator. Therefore, there is a table (`compilerprocs`)
with all symbols that are marked as `compilerproc`. `compilerprocs` are
needed by the code generator. A `magic` proc is not the same as a
`compilerproc`: A `magic` is a proc that needs compiler magic for its
@@ -524,7 +524,7 @@ This should produce roughly this code:
proc add(x: int): tuple[prc, data: EnvX] =
var ex: EnvX
ex.x = x
result = (labmdaY, ex)
result = (lambdaY, ex)
var tmp = add(2)
var tmp2 = tmp.fn(4, tmp.data)
@@ -566,12 +566,12 @@ Internals
---------
Lambda lifting is implemented as part of the `transf` pass. The `transf`
pass generates code to setup the environment and to pass it around. However,
pass generates code to set up the environment and to pass it around. However,
this pass does not change the types! So we have some kind of mismatch here; on
the one hand the proc expression becomes an explicit tuple, on the other hand
the tyProc(ccClosure) type is not changed. For C code generation it's also
important the hidden formal param is `void*`:c: and not something more
specialized. However the more specialized env type needs to passed to the
specialized. However, the more specialized env type needs to passed to the
backend somehow. We deal with this by modifying `s.ast[paramPos]` to contain
the formal hidden parameter, but not `s.typ`!
@@ -586,14 +586,14 @@ Integer literals
----------------
In Nim, there is a redundant way to specify the type of an
integer literal. First of all, it should be unsurprising that every
integer literal. First, it should be unsurprising that every
node has a node kind. The node of an integer literal can be any of the
following values::
nkIntLit, nkInt8Lit, nkInt16Lit, nkInt32Lit, nkInt64Lit,
nkUIntLit, nkUInt8Lit, nkUInt16Lit, nkUInt32Lit, nkUInt64Lit
On top of that, there is also the `typ` field for the type. It the
On top of that, there is also the `typ` field for the type. The
kind of the `typ` field can be one of the following ones, and it
should be matching the literal kind::

View File

@@ -91,7 +91,7 @@ The nature of this executable depends on the compiler implementation; it may,
for example, be a native binary or JavaScript source code.
In a typical Nim program, most of the code is compiled into the executable.
However, some of the code may be executed at
However, some code may be executed at
`compile-time`:idx:. This can include constant expressions, macro definitions,
and Nim procedures used by macro definitions. Most of the Nim language is
supported at compile-time, but there are some restrictions -- see `Restrictions
@@ -114,7 +114,7 @@ provides a means to disable these `runtime checks`:idx:. See the section
pragmas_ for details.
Whether a panic results in an exception or in a fatal error is
implementation specific. Thus the following program is invalid; even though the
implementation specific. Thus, the following program is invalid; even though the
code purports to catch the `IndexDefect` from an out-of-bounds array access, the
compiler may instead choose to allow the program to die with a fatal error.
@@ -127,7 +127,7 @@ compiler may instead choose to allow the program to die with a fatal error.
echo "invalid index"
```
The current implementation allows to switch between these different behaviors
The current implementation allows switching between these different behaviors
via `--panics:on|off`:option:. When panics are turned on, the program dies with a
panic, if they are turned off the runtime errors are turned into
exceptions. The benefit of `--panics:on`:option: is that it produces smaller binary
@@ -388,7 +388,7 @@ contain the following `escape sequences`:idx:\ :
================== ===================================================
Strings in Nim may contain any 8-bit value, even embedded zeros. However
Strings in Nim may contain any 8-bit value, even embedded zeros. However,
some operations may interpret the first binary zero as a terminator.
@@ -502,7 +502,7 @@ The `Rune` type can represent any Unicode character.
`Rune` is declared in the `unicode module <unicode.html>`_.
A character literal that does not end in `'` is interpreted as `'` if there
is a preceeding backtick token. There must be no whitespace between the preceeding
is a preceding backtick token. There must be no whitespace between the preceding
backtick token and the character literal. This special case ensures that a declaration
like ``proc `'customLiteral`(s: string)`` is valid. ``proc `'customLiteral`(s: string)``
is the same as ``proc `'\''customLiteral`(s: string)``.
@@ -566,8 +566,8 @@ an expression `-128'i8` should be valid and without this special case, this woul
be impossible -- `128` is not a valid `int8` value, only `-128` is.
For the `unary_minus` rule there are further restrictions that are not covered
in the formal grammar. For `-` to be part of the number literal its immediately
preceeding character has to be in the
in the formal grammar. For `-` to be part of the number literal the immediately
preceding character has to be in the
set `{' ', '\t', '\n', '\r', ',', ';', '(', '[', '{'}`. This set was designed to
cover most cases in a natural manner.
@@ -1224,7 +1224,7 @@ The size of the bool type is one byte.
Character type
--------------
The character type is named `char` in Nim. Its size is one byte.
Thus it cannot represent a UTF-8 character, but a part of it.
Thus, it cannot represent a UTF-8 character, but a part of it.
The `Rune` type is used for Unicode characters, it can represent any Unicode
character. `Rune` is declared in the `unicode module <unicode.html>`_.
@@ -1255,7 +1255,7 @@ Now the following holds::
ord(Direction.west) == 3
The implied order is: north < east < south < west. The comparison operators can be used
with enumeration types. Instead of `north` etc, the enum value can also
with enumeration types. Instead of `north` etc., the enum value can also
be qualified with the enum type that it resides in, `Direction.north`.
For better interfacing to other programming languages, the fields of enum
@@ -1405,7 +1405,7 @@ memory. For this reason, the implicit conversion will be removed in future
releases of the Nim compiler. Certain idioms like conversion of a `const` string
to `cstring` are safe and will remain to be allowed.
A `$` proc is defined for cstrings that returns a string. Thus to get a nim
A `$` proc is defined for cstrings that returns a string. Thus, to get a nim
string from a cstring:
```nim
@@ -1911,7 +1911,7 @@ point to and modify the same location in memory (also called `aliasing`:idx:).
Nim distinguishes between `traced`:idx: and `untraced`:idx: references.
Untraced references are also called *pointers*. Traced references point to
objects of a garbage-collected heap, untraced references point to
manually allocated objects or objects somewhere else in memory. Thus
manually allocated objects or objects somewhere else in memory. Thus,
untraced references are *unsafe*. However, for certain low-level operations
(accessing the hardware) untraced references are unavoidable.
@@ -1922,7 +1922,7 @@ convertible to the `pointer` type.
An empty subscript `[]` notation can be used to de-refer a reference,
the `addr` procedure returns the address of an item. An address is always
an untraced reference.
Thus the usage of `addr` is an *unsafe* feature.
Thus, the usage of `addr` is an *unsafe* feature.
The `.` (access a tuple/object field operator)
and `[]` (array/string/sequence index operator) operators perform implicit
@@ -2119,7 +2119,7 @@ Nim supports these `calling conventions`:idx:\:
The inline convention means the caller should not call the procedure,
but inline its code directly. Note that Nim does not inline, but leaves
this to the C compiler; it generates `__inline` procedures. This is
only a hint for the compiler: it may completely ignore it and
only a hint for the compiler: it may completely ignore it, and
it may inline procedures that are not marked as `inline`.
`fastcall`:idx:
@@ -2902,7 +2902,7 @@ the variable has been initialized and does not rely on syntactic properties:
# use x
```
`requiresInit` pragma can also be applyied to `distinct` types.
`requiresInit` pragma can also be applied to `distinct` types.
Given the following distinct type definitions:
@@ -2929,7 +2929,7 @@ The following code blocks will fail to compile:
doAssert string(s) == "test"
```
But these ones will compile successfully:
But these will compile successfully:
```nim
let foo = DistinctFoo(Foo(x: "test"))
@@ -3039,7 +3039,7 @@ Example:
The `if` statement is a simple way to make a branch in the control flow:
The expression after the keyword `if` is evaluated, if it is true
the corresponding statements after the `:` are executed. Otherwise
the corresponding statements after the `:` are executed. Otherwise,
the expression after the `elif` is evaluated (if there is an
`elif` branch), if it is true the corresponding statements after
the `:` are executed. This goes on until the last `elif`. If all
@@ -3583,7 +3583,7 @@ that is a type class (which is non-concrete) would be invalid:
Type casts should not be confused with *type conversions,* as mentioned in the
prior section. Unlike type conversions, a type cast cannot change the underlying
bit pattern of the data being casted (aside from that the size of the target type
bit pattern of the data being cast (aside from that the size of the target type
may differ from the source type). Casting resembles *type punning* in other
languages or C++'s `reinterpret_cast`:cpp: and `bit_cast`:cpp: features.
@@ -3673,8 +3673,8 @@ arguments, by using the type modifier `var`.
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 doesn't have a 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:
@@ -3692,7 +3692,7 @@ best match for the arguments. Example:
result[i] = toLower(s[i]) # calls toLower for characters; no recursion!
```
Calling a procedure can be done in many different ways:
Calling a procedure can be done in many ways:
```nim
proc callme(x, y: int, s: string = "", c: char, b: bool = false) = ...
@@ -4029,7 +4029,7 @@ simplicity (they require specialized semantic checking)::
declared, defined, definedInScope, compiles, sizeof,
is, shallowCopy, getAst, astToStr, spawn, procCall
Thus they act more like keywords than like ordinary identifiers; unlike a
Thus, they act more like keywords than like ordinary identifiers; unlike a
keyword however, a redefinition may `shadow`:idx: the definition in
the system_ module. From this list the following should not be written in dot
notation `x.f` since `x` cannot be type-checked before it gets passed
@@ -4367,7 +4367,7 @@ state are automatically saved between calls. Example:
echo ch
```
The compiler generates code as if the programmer would have written this:
The compiler generates code as if the programmer had written this:
```nim
var i = 0
@@ -4387,7 +4387,7 @@ Implicit items/pairs invocations
If the for loop expression `e` does not denote an iterator and the for loop
has exactly 1 variable, the for loop expression is rewritten to `items(e)`;
ie. an `items` iterator is implicitly invoked:
i.e. an `items` iterator is implicitly invoked:
```nim
for x in [1,2,3]: echo x
@@ -4490,7 +4490,7 @@ The builtin `system.finished` can be used to determine if an iterator has
finished its operation; no exception is raised on an attempt to invoke an
iterator that has already finished its work.
Note that `system.finished` is error prone to use because it only returns
Note that `system.finished` is error-prone to use because it only returns
`true` one iteration after the iterator has finished:
```nim
@@ -4511,7 +4511,7 @@ Note that `system.finished` is error prone to use because it only returns
0
```
Instead this code has to be used:
Instead, this code has to be used:
```nim
var c = mycount # instantiate the iterator
@@ -4562,7 +4562,7 @@ The call can be made more like an inline iterator with a for loop macro:
echo f
```
Because of full backend function call aparatus involvment, closure iterator
Because of full backend function call apparatus involvement, closure iterator
invocation is typically higher cost than inline iterators. Adornment by
a macro wrapper at the call site like this is a possibly useful reminder.
@@ -5052,7 +5052,7 @@ conservative in its effect analysis:
proc cmpE(a, b: MyInt): int {.raises: [Exception].} =
cmp(a.int, b.int)
proc harmfull {.raises: [].} =
proc harmful {.raises: [].} =
# does not compile, `sort` can now raise Exception
toSort.sort cmpE
```
@@ -5921,7 +5921,7 @@ template parameter, it is an `inject`'ed symbol:
The `inject` and `gensym` pragmas are second class annotations; they have
no semantics outside of a template definition and cannot be abstracted over:
no semantics outside a template definition and cannot be abstracted over:
```nim
{.pragma myInject: inject.}
@@ -5972,7 +5972,7 @@ Limitations of the method call syntax
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
rewritten to `f(x)`. Therefore the dot syntax has some limitations when it
rewritten to `f(x)`. Therefore, the dot syntax has some limitations when it
is used to invoke templates/macros:
```nim test = "nim c $1" status = 1
@@ -6456,7 +6456,7 @@ Modules
Nim supports splitting a program into pieces by a module concept.
Each module needs to be in its own file and has its own `namespace`:idx:.
Modules enable `information hiding`:idx: and `separate compilation`:idx:.
A module may gain access to symbols of another module by the `import`:idx:
A module may gain access to the symbols of another module by the `import`:idx:
statement. `Recursive module dependencies`:idx: are allowed, but are slightly
subtle. Only top-level symbols that are marked with an asterisk (`*`) are
exported. A valid module name can only be a valid Nim identifier (and thus its
@@ -6529,7 +6529,7 @@ statement is useful to split up a large module into several files:
include fileA, fileB, fileC
```
The `include` statement can be used outside of the top level, as such:
The `include` statement can be used outside the top level, as such:
```nim
# Module A
@@ -6564,8 +6564,8 @@ in subdirectories:
import lib/pure/os, "lib/pure/times"
```
Note that the module name is still `strutils` and not `lib/pure/strutils`
and so one **cannot** do:
Note that the module name is still `strutils` and not `lib/pure/strutils`,
thus one **cannot** do:
```nim
import lib/pure/strutils
@@ -6614,7 +6614,7 @@ It is recommended and preferred but not currently enforced that all stdlib modul
From import statement
---------------------
After the `from` statement, a module name follows followed by
After the `from` statement, a module name followed by
an `import` to list the symbols one likes to use without explicit
full qualification:
@@ -6964,7 +6964,7 @@ statement, as seen in stack backtraces:
raise newException(AssertionDefect, msg)
```
If the `line` pragma is used with a parameter, the parameter needs be a
If the `line` pragma is used with a parameter, the parameter needs to be a
`tuple[filename: string, line: int]`. If it is used without a parameter,
`system.instantiationInfo()` is used.
@@ -6987,7 +6987,7 @@ statement:
```
In the example, the case branches `0` and `1` are much more common than
the other cases. Therefore the generated assembler code should test for these
the other cases. Therefore, the generated assembler code should test for these
values first so that the CPU's branch predictor has a good chance to succeed
(avoiding an expensive CPU pipeline stall). The other cases might be put into a
jump table for O(1) overhead but at the cost of a (very likely) pipeline
@@ -7323,14 +7323,14 @@ restriction is violated, the backend optimizer is free to miscompile the code.
This is an **unsafe** language feature.
Ideally in later versions of the language, the restriction will be enforced at
compile time. (This is also why the name `noalias` was choosen instead of a more
compile time. (This is also why the name `noalias` was chosen instead of a more
verbose name like `unsafeAssumeNoAlias`.)
Volatile pragma
---------------
The `volatile` pragma is for variables only. It declares the variable as
`volatile`:c:, whatever that means in C/C++ (its semantics are not well defined
`volatile`:c:, whatever that means in C/C++ (its semantics are not well-defined
in C/C++).
**Note**: This pragma will not exist for the LLVM backend.
@@ -7421,7 +7421,7 @@ The `link` pragma can be used to link an additional file with the project:
passc pragma
------------
The `passc` pragma can be used to pass additional parameters to the C
compiler like one would using the command-line switch `--passc`:option:\:
compiler like one would use the command-line switch `--passc`:option:\:
```Nim
{.passc: "-Wall -Werror".}
@@ -7976,7 +7976,7 @@ implementation:
user_id {.dbForeignKey: User.}: int
read_access: bool
write_access: bool
admin_acess: bool
admin_access: bool
```
In this example, custom pragmas are used to describe how Nim objects are
@@ -8020,7 +8020,7 @@ Macro pragmas
-------------
Macros and templates can sometimes be called with the pragma syntax. Cases
where this is possible include when attached to routine (procs, iterators, etc)
where this is possible include when attached to routine (procs, iterators, etc.)
declarations or routine type expressions. The compiler will perform the
following simple syntactic transformations:
@@ -8190,7 +8190,7 @@ strings automatically:
Union pragma
------------
The `union` pragma can be applied to any `object` type. It means all
of the object's fields are overlaid in memory. This produces a `union`:c:
of an object's fields are overlaid in memory. This produces a `union`:c:
instead of a `struct`:c: in the generated C/C++ code. The object declaration
then must not use inheritance or any GC'ed memory but this is currently not
checked.
@@ -8435,7 +8435,7 @@ The guard then needs to be another field within the same object or a
global variable.
Since objects can reside on the heap or on the stack, this greatly enhances
the expressivity of the language:
the expressiveness of the language:
```nim
import std/locks

View File

@@ -61,7 +61,7 @@ You can annotate a type where nil isn't a valid value with `not nil`.
If a type can include `nil` as a valid value, dereferencing values of the type
is checked by the compiler: if a value which might be nil is derefenced, this
is checked by the compiler: if a value which might be nil is dereferenced, this
produces a warning by default, you can turn this into an error using
the compiler options `--warningAsError:strictNotNil`:option:.
@@ -76,7 +76,7 @@ Note: test that/TODO for code/manual.
nilability state
-----------------
Currently a nilable value can be `Safe`, `MaybeNil` or `Nil` : we use internally `Parent` and `Unreachable` but this is an implementation detail(a parent layer has the actual nilability).
Currently, a nilable value can be `Safe`, `MaybeNil` or `Nil` : we use internally `Parent` and `Unreachable` but this is an implementation detail(a parent layer has the actual nilability).
- `Safe` means it shouldn't be nil at that point: e.g. after assignment to
a non-nil value or `not a.isNil` check
@@ -87,7 +87,7 @@ Currently a nilable value can be `Safe`, `MaybeNil` or `Nil` : we use internally
- `Unreachable` means it shouldn't be possible to access this in this branch:
so we do generate a warning as well.
We show an error for each dereference (`[]`, `.field`, `[index]` `()` etc) which is of a tracked expression which is
We show an error for each dereference (`[]`, `.field`, `[index]` `()` etc.) which is of a tracked expression which is
in `MaybeNil` or `Nil` state.
@@ -127,14 +127,14 @@ This is also a possible aliasing `move out` (moving out of a current alias set).
.. code-block:: nim
call(a)
Here `call` can change a field or element of `a`, so if we have a dependant expression of `a` : e.g. `a.field`. Dependats become `MaybeNil`.
Here `call` can change a field or element of `a`, so if we have a dependant expression of `a` : e.g. `a.field`. Dependants become `MaybeNil`.
branches rules
---------------
Branches are the reason we do nil checking like this: with flow checking.
Sources of brancing are `if`, `while`, `for`, `and`, `or`, `case`, `try` and combinations with `return`, `break`, `continue` and `raise`
Sources of branching are `if`, `while`, `for`, `and`, `or`, `case`, `try` and combinations with `return`, `break`, `continue` and `raise`
We create a new layer/"scope" for each branch where we map expressions to nilability. This happens when we "fork": usually on the beginning of a construct.
When branches "join" we usually unify their expression maps or/and nilabilities.
@@ -164,7 +164,7 @@ We want to track also field(dot) and index(bracket) expressions.
We track some of those compound expressions which might be nilable as dependants of their bases: `a.field` is changed if `a` is moved (re-assigned),
similarly `a[index]` is dependent on `a` and `a.field.field` on `a.field`.
When we move the base, we update dependants to `MaybeNil`. Otherwise we usually start with type nilability.
When we move the base, we update dependants to `MaybeNil`. Otherwise, we usually start with type nilability.
When we call args, we update the nilability of their dependants to `MaybeNil` as the calls usually can change them.
We might need to check for `strictFuncs` pure funcs and not do that then.
@@ -172,10 +172,10 @@ We might need to check for `strictFuncs` pure funcs and not do that then.
For field expressions `a.field`, we calculate an integer value based on a hash of the tree and just accept equivalent trees as equivalent expressions.
For item expression `a[index]`, we also calculate an integer value based on a hash of the tree and accept equivalent trees as equivalent expressions: for static values only.
For now we support only constant indices: we dont track expression with no-const indices. For those we just report a warning even if they are safe for now: one can use a local variable to workaround. For loops this might be annoying: so one should be able to turn off locally the warning using the `{.warning[StrictNotNil]:off.}`.
For now, we support only constant indices: we don't track expression with no-const indices. For those we just report a warning even if they are safe for now: one can use a local variable to workaround. For loops this might be annoying: so one should be able to turn off locally the warning using the `{.warning[StrictNotNil]:off.}`.
For bracket expressions, in the future we might count `a[<any>]` as the same general expression.
This means we should should the index but otherwise handle it the same for assign (maybe "aliasing" all the non-static elements) and differentiate only for static: e.g. `a[0]` and `a[1]`.
This means we should the index but otherwise handle it the same for assign (maybe "aliasing" all the non-static elements) and differentiate only for static: e.g. `a[0]` and `a[1]`.
element tracking
-----------------
@@ -193,7 +193,7 @@ unstructured control flow rules
-------------------------------
Unstructured control flow keywords as `return`, `break`, `continue`, `raise` mean that we jump from a branch out.
This means that if there is code after the finishing of the branch, it would be ran if one hasn't hit the direct parent branch of those: so it is similar to an `else`. In those cases we should use the reverse nilabilities for the local to the condition expressions. E.g.
This means that if there is code after the finishing of the branch, it would be run if one hasn't hit the direct parent branch of those: so it is similar to an `else`. In those cases we should use the reverse nilabilities for the local to the condition expressions. E.g.
.. code-block:: nim
for a in c:
@@ -235,7 +235,7 @@ TODO
warnings and errors
---------------------
We show an error for each dereference (`[]`, `.field`, `[index]` `()` etc) which is of a tracked expression which is
We show an error for each dereference (`[]`, `.field`, `[index]` `()` etc.) which is of a tracked expression which is
in `MaybeNil` or `Nil` state.
We might also show a history of the transitions and the reasons for them that might change the nilability of the expression.

View File

@@ -30,7 +30,7 @@ Positional arguments, from left to right:
For any given DIRECTORY nimgrep searches only its immediate files without
traversing sub-directories unless `--recursive` is specified.
traversing subdirectories unless `--recursive` is specified.
In replacement mode we require all 3 positional arguments to avoid damaging.
@@ -47,15 +47,15 @@ Options:
nimgrep --filenames "" DIRECTORY
# Note empty pattern "", lists all files in DIRECTORY
* Interprete patterns:
* Interpret patterns:
--peg PATTERN and PAT are Peg
--re PATTERN and PAT are regular expressions (default)
--rex, -x use the "extended" syntax for the regular expression
so that whitespace is not significant
--word, -w matches should have word boundaries (buggy for pegs!)
--ignoreCase, -i be case insensitive in PATTERN and PAT
--ignoreCase, -i be case-insensitive in PATTERN and PAT
--ignoreStyle, -y be style insensitive in PATTERN and PAT
.. Note:: PATERN and patterns PAT (see below in other options) are all either
.. Note:: PATTERN and patterns PAT (see below in other options) are all either
Regex or Peg simultaneously and options `--rex`, `--word`, `--ignoreCase`,
and `--ignoreStyle` are applied to all of them.

View File

@@ -13,12 +13,12 @@ notation meaning
``A / ... / Z`` Ordered choice: Apply expressions `A`, ..., `Z`, in this
order, to the text ahead, until one of them succeeds and
possibly consumes some text. Indicate success if one of
expressions succeeded. Otherwise do not consume any text
expressions succeeded. Otherwise, do not consume any text
and indicate failure.
``A ... Z`` Sequence: Apply expressions `A`, ..., `Z`, in this order,
to consume consecutive portions of the text ahead, as long
as they succeed. Indicate success if all succeeded.
Otherwise do not consume any text and indicate failure.
Otherwise, do not consume any text and indicate failure.
The sequence's precedence is higher than that of ordered
choice: ``A B / C`` means ``(A B) / Z`` and
not ``A (B / Z)``.
@@ -44,20 +44,20 @@ notation meaning
``E+`` One or more: Apply expression `E` repeatedly to match
the text ahead, as long as it succeeds. Consume the matched
text (if any) and indicate success if there was at least
one match. Otherwise indicate failure.
one match. Otherwise, indicate failure.
``E*`` Zero or more: Apply expression `E` repeatedly to match
the text ahead, as long as it succeeds. Consume the matched
text (if any). Always indicate success.
``E?`` Zero or one: If expression `E` matches the text ahead,
consume it. Always indicate success.
``[s]`` Character class: If the character ahead appears in the
string `s`, consume it and indicate success. Otherwise
string `s`, consume it and indicate success. Otherwise,
indicate failure.
``[a-b]`` Character range: If the character ahead is one from the
range `a` through `b`, consume it and indicate success.
Otherwise indicate failure.
Otherwise, indicate failure.
``'s'`` String: If the text ahead is the string `s`, consume it
and indicate success. Otherwise indicate failure.
and indicate success. Otherwise, indicate failure.
``i's'`` String match ignoring case.
``y's'`` String match ignoring style.
``v's'`` Verbatim string match: Use this to override a global
@@ -66,15 +66,15 @@ notation meaning
``y$j`` String match ignoring style for back reference.
``v$j`` Verbatim string match for back reference.
``.`` Any character: If there is a character ahead, consume it
and indicate success. Otherwise (that is, at the end of
and indicate success. Otherwise, (that is, at the end of
input) indicate failure.
``_`` Any Unicode character: If there is an UTF-8 character
ahead, consume it and indicate success. Otherwise indicate
``_`` Any Unicode character: If there is a UTF-8 character
ahead, consume it and indicate success. Otherwise, indicate
failure.
``@E`` Search: Shorthand for ``(!E .)* E``. (Search loop for the
pattern `E`.)
``{@} E`` Captured Search: Shorthand for ``{(!E .)*} E``. (Search
loop for the pattern `E`.) Everything until and exluding
loop for the pattern `E`.) Everything until and excluding
`E` is captured.
``@@ E`` Same as ``{@} E``.
``A <- E`` Rule: Bind the expression `E` to the *nonterminal symbol*
@@ -82,7 +82,7 @@ notation meaning
matching engine.**
``\identifier`` Built-in macro for a longer expression.
``\ddd`` Character with decimal code *ddd*.
``\"``, etc Literal ``"``, etc.
``\"``, etc. Literal ``"``, etc.
=============== ============================================================

View File

@@ -1,5 +1,5 @@
============================
Nim's documenation system
Nim's documentation system
============================
This folder contains Nim's documentation. The documentation

View File

@@ -8,7 +8,7 @@
Testament is an advanced automatic unittests runner for Nim tests, is used for the development of Nim itself,
offers process isolation for your tests, it can generate statistics about test cases,
supports multiple targets (C, C++, ObjectiveC, JavaScript, etc),
supports multiple targets (C, C++, ObjectiveC, JavaScript, etc.),
simulated `Dry-Runs <https://en.wikipedia.org/wiki/Dry_run_(testing)>`_,
has logging, can generate HTML reports, skip tests from a file, and more,
so can be useful to run your tests, even the most complex ones.
@@ -17,7 +17,7 @@ so can be useful to run your tests, even the most complex ones.
Test files location
===================
By default Testament looks for test files on ``"./tests/*.nim"``.
By default, Testament looks for test files on ``"./tests/*.nim"``.
You can overwrite this pattern glob using `pattern <glob>`:option:.
The default working directory path can be changed using
`--directory:"folder/subfolder/"`:option:.
@@ -42,7 +42,7 @@ Options
or doing anything else.
--colors:on|off Turn messages coloring on|off.
--backendLogging:on|off Disable or enable backend logging.
By default turned on.
By default, turned on.
--skipFrom:file Read tests to skip from ``file`` - one test per
line, # comments ignored
@@ -88,8 +88,8 @@ you have to run at least 1 test *before* generating a report:
$ testament html
Writing Unitests
================
Writing Unit tests
==================
Example "template" **to edit** and write a Testament unittest:
@@ -112,7 +112,7 @@ Example "template" **to edit** and write a Testament unittest:
exitcode: 0
# Provide an `output` string to assert that the test prints to standard out
# exatly the expected string. Provide an `outputsub` string to assert that
# exactly the expected string. Provide an `outputsub` string to assert that
# the string given here is a substring of the standard out output of the
# test.
output: ""
@@ -139,7 +139,7 @@ Example "template" **to edit** and write a Testament unittest:
# Can be run in batch mode, or not.
batchable: true
# Can be run Joined with other tests to run all togheter, or not.
# Can be run Joined with other tests to run all together, or not.
joinable: true
# On Linux 64-bit machines, whether to use Valgrind to check for bad memory
@@ -192,8 +192,8 @@ Example "template" **to edit** and write a Testament unittest:
* `Testament supports inlined error messages on Unittests, basically comments with the expected error directly on the code. <https://github.com/nim-lang/Nim/blob/9a110047cbe2826b1d4afe63e3a1f5a08422b73f/tests/effects/teffects1.nim>`_
Unitests Examples
=================
Unit test Examples
==================
Expected to fail:

View File

@@ -74,7 +74,7 @@ aiming for your debugging pleasure. With ``-d:release`` some checks are
For benchmarking or production code, use the ``-d:release`` switch.
For comparing the performance with unsafe languages like C, use the ``-d:danger`` switch
in order to get meaningful, comparable results. Otherwise Nim might be handicapped
in order to get meaningful, comparable results. Otherwise, Nim might be handicapped
by checks that are **not even available** for C.
Though it should be pretty obvious what the program does, I will explain the
@@ -290,8 +290,8 @@ characters.)
Case statement
--------------
Another way to branch is provided by the case statement. A case statement is
a multi-branch:
Another way to branch is provided by the case statement. A case statement allows
for multiple branches:
.. code-block:: nim
:test: "nim c $1"
@@ -732,7 +732,7 @@ Named arguments
Often a procedure has many parameters and it is not clear in which order the
parameters appear. This is especially true for procedures that construct a
complex data type. Therefore the arguments to a procedure can be named, so
complex data type. Therefore, the arguments to a procedure can be named, so
that it is clear which argument belongs to which parameter:
.. code-block:: nim
@@ -893,7 +893,7 @@ with `{.noSideEffects.}`. Functions can still change their mutable arguments
however, which are those marked as `var`, along with any `ref` objects.
Unlike procedures, methods are dynamically dispatched. This sounds a bit
complicated, but it is a concept closely related to inheritance and object oriented
complicated, but it is a concept closely related to inheritance and object-oriented
programming. If you overload a procedure (two procedures with the same name but
of different types or with different sets of arguments are said to be overloaded), the procedure to use is determined
at compile-time. Methods, on the other hand, depend on objects that inherit from
@@ -950,7 +950,7 @@ important differences:
However, you can also use a closure iterator to get a different set of
restrictions. See `first-class iterators <manual.html#iterators-and-the-for-statement-firstminusclass-iterators>`_
for details. Iterators can have the same name and parameters as a proc since
essentially they have their own namespaces. Therefore it is common practice to
essentially they have their own namespaces. Therefore, it is common to
wrap iterators in procs of the same name which accumulate the result of the
iterator and return it as a sequence, like `split` from the `strutils module
<strutils.html>`_.
@@ -966,8 +966,8 @@ Booleans
--------
Nim's boolean type is called `bool` and consists of the two
pre-defined values `true` and `false`. Conditions in while,
if, elif, and when statements must be of type bool.
pre-defined values `true` and `false`. Conditions in `while`,
`if`, `elif`, and `when` statements must be of type bool.
The operators `not, and, or, xor, <, <=, >, >=, !=, ==` are defined
for the bool type. The `and` and `or` operators perform short-circuit
@@ -985,7 +985,7 @@ Characters
The *character type* is called `char`. Its size is always one byte, so
it cannot represent most UTF-8 characters, but it *can* represent one of the bytes
that makes up a multi-byte UTF-8 character.
that makes up a multibyte UTF-8 character.
The reason for this is efficiency: for the overwhelming majority of use-cases,
the resulting programs will still handle UTF-8 properly as UTF-8 was especially
designed for this.
@@ -1485,7 +1485,7 @@ slice's bounds can hold any value supported by
their type, but it is the proc using the slice object which defines what values
are accepted.
To understand some of the different ways of specifying the indices of
To understand the different ways of specifying the indices of
strings, arrays, sequences, etc., it must be remembered that Nim uses
zero-based indices.
@@ -1500,7 +1500,7 @@ indices are
^19 ^8 ^2 using ^ syntax
where `b[0 .. ^1]` is equivalent to `b[0 .. b.len-1]` and `b[0 ..< b.len]`, and it
can be seen that the `^1` provides a short-hand way of specifying the `b.len-1`. See
can be seen that the `^1` provides a shorthand way of specifying the `b.len-1`. See
the `backwards index operator <system.html#^.t%2Cint>`_.
In the above example, because the string ends in a period, to get the portion of the
@@ -1685,7 +1685,7 @@ Tuple unpacking is also supported in for-loops:
echo i, c
# This will output: 0a; 1b; 2c
Fields of tuples are always public, they don't need to be explicity
Fields of tuples are always public, they don't need to be explicitly
marked to be exported, unlike for example fields in an object type.
@@ -1699,7 +1699,7 @@ point to and modify the same location in memory.
Nim distinguishes between `traced`:idx: and `untraced`:idx: references.
Untraced references are also called *pointers*. Traced references point to
objects in a garbage-collected heap, untraced references point to
manually allocated objects or objects elsewhere in memory. Thus
manually allocated objects or objects elsewhere in memory. Thus,
untraced references are *unsafe*. However, for certain low-level operations
(e.g. accessing the hardware), untraced references are necessary.