promote std prefix in docs (#17128)

This commit is contained in:
flywind
2021-02-21 00:38:29 -06:00
committed by GitHub
parent 778f124af0
commit 69a78c9183
9 changed files with 41 additions and 41 deletions

View File

@@ -106,7 +106,7 @@ sample.nim:
.. code-block:: nim
## This module is a sample.
import strutils
import std/strutils
proc helloWorld*(times: int) =
## Takes an integer and outputs

View File

@@ -258,7 +258,7 @@ as a "shallow" tree. Let's assume we compile module ``m`` with the
following contents:
.. code-block:: nim
import strutils
import std/strutils
var x*: int = 90
{.compile: "foo.c".}
@@ -270,7 +270,7 @@ following contents:
Conceptually this is the AST we store for the module:
.. code-block:: nim
import strutils
import std/strutils
var x*
{.compile: "foo.c".}

View File

@@ -830,7 +830,7 @@ problem!)
.. code-block:: nim
:test: "nim c $1"
import strformat
import std/strformat
var fib_n {.compileTime.}: int
var fib_prev {.compileTime.}: int
@@ -2113,7 +2113,7 @@ modeled as a string. However, using string templates and filling in the
values is vulnerable to the famous `SQL injection attack`:idx:\:
.. code-block:: nim
import strutils
import std/strutils
proc query(db: DbHandle, statement: string) = ...
@@ -2145,7 +2145,7 @@ subtype relation between the abstract type and its base type. Explicit type
conversions from ``string`` to ``SQL`` are allowed:
.. code-block:: nim
import strutils, sequtils
import std/[strutils, sequtils]
proc properQuote(s: string): SQL =
# quotes a string properly for an SQL statement
@@ -2791,7 +2791,7 @@ Const section
A const section declares constants whose values are constant expressions:
.. code-block::
import strutils
import std/[strutils]
const
roundPi = 3.1415
constEval = contains("abc", 'b') # computed at compile time!
@@ -4193,7 +4193,7 @@ parameters of an outer factory proc:
The call can be made more like an inline iterator with a for loop macro:
.. code-block:: nim
import macros
import std/macros
macro toItr(x: ForLoopStmt): untyped =
let expr = x[0]
let call = x[1][1] # Get foo out of toItr(foo)
@@ -4327,7 +4327,7 @@ needs to fit the types of ``except`` branches, but the type of the ``finally``
branch always has to be ``void``:
.. code-block:: nim
from strutils import parseInt
from std/strutils import parseInt
let x = try: parseInt("133a")
except: -1
@@ -5423,7 +5423,7 @@ Another common example is this:
:test: "nim c $1"
:status: 1
from sequtils import toSeq
from std/sequtils import toSeq
iterator something: string =
yield "Hello"
@@ -5443,7 +5443,7 @@ binds to symbols prohibits this.
:test: "nim c $1"
:status: 1
import sequtils
import std/sequtils
var myItems = @[1,3,3,7]
let N1 = count(myItems, 3) # OK
@@ -5489,7 +5489,7 @@ variable number of arguments:
# to work with Nim syntax trees, we need an API that is defined in the
# ``macros`` module:
import macros
import std/macros
macro debug(args: varargs[untyped]): untyped =
# `args` is a collection of `NimNode` values that each contain the
@@ -5548,7 +5548,7 @@ builtin can be used for that:
.. code-block:: nim
:test: "nim c $1"
import macros
import std/macros
macro debug(n: varargs[typed]): untyped =
result = newNimNode(nnkStmtList, n)
@@ -5596,7 +5596,7 @@ statement. The following example should show how this feature could be
used for a lexical analyzer.
.. code-block:: nim
import macros
import std/macros
macro case_token(args: varargs[untyped]): untyped =
echo args.treeRepr
@@ -5633,7 +5633,7 @@ type ``system.ForLoopStmt`` can rewrite the entirety of a ``for`` loop:
.. code-block:: nim
:test: "nim c $1"
import macros
import std/macros
macro enumerate(x: ForLoopStmt): untyped =
expectKind x, nnkForStmt
@@ -5716,7 +5716,7 @@ One can force an expression to be evaluated at compile time as a constant
expression by coercing it to a corresponding ``static`` type:
.. code-block:: nim
import math
import std/math
echo static(fac(5)), " ", static[bool](16.isPowerOfTwo)
@@ -5796,7 +5796,7 @@ simply passed as a ``NimNode`` to the macro, like everything else.
.. code-block:: nim
import macros
import std/macros
macro forwardType(arg: typedesc): typedesc =
# ``arg`` is of type ``NimNode``
@@ -6214,7 +6214,7 @@ but accessed at runtime:
.. code-block:: nim
:test: "nim c -r $1"
import macros
import std/macros
var nameToProc {.compileTime.}: seq[(string, proc (): string {.nimcall.})]
@@ -6607,7 +6607,7 @@ is uncertain (it may be removed at any time).
Example:
.. code-block:: nim
import threadpool
import std/threadpool
{.experimental: "parallel".}
proc threadedEcho(s: string, i: int) =
@@ -7587,7 +7587,7 @@ The ``dynlib`` pragma supports not only constant strings as an argument but also
string expressions in general:
.. code-block:: nim
import os
import std/os
proc getDllName: string =
result = "mylib.dll"

View File

@@ -606,7 +606,7 @@ The concept types can be parametric just like the regular generic types:
.. code-block:: nim
### matrixalgo.nim
import typetraits
import std/typetraits
type
AnyMatrix*[R, C: static int; T] = concept m, var mvar, type M
@@ -743,7 +743,7 @@ type is an instance of it:
.. code-block:: nim
:test: "nim c $1"
import sugar, typetraits
import std/[sugar, typetraits]
type
Functor[A] = concept f
@@ -761,7 +761,7 @@ type is an instance of it:
# the Functor to a instance of a different type, given
# a suitable `map` operation for the enclosed values
import options
import std/options
echo Option[int] is Functor # prints true
@@ -989,7 +989,7 @@ equality operator for tuples (as provided in ``system.==``):
{.experimental: "caseStmtMacros".}
import macros
import std/macros
macro `case`(n: tuple): untyped =
result = newTree(nnkIfStmt)
@@ -1259,7 +1259,7 @@ The ``**`` is much like the ``*`` operator, except that it gathers not only
all the arguments, but also the matched operators in reverse polish notation:
.. code-block:: nim
import macros
import std/macros
type
Matrix = object
@@ -1331,7 +1331,7 @@ Example: Hoisting
The following example shows how some form of hoisting can be implemented:
.. code-block:: nim
import pegs
import std/pegs
template optPeg{peg(pattern)}(pattern: string{lit}): Peg =
var gl {.global, gensym.} = peg(pattern)
@@ -1405,7 +1405,7 @@ Spawn statement
`spawn`:idx: can be used to pass a task to the thread pool:
.. code-block:: nim
import threadpool
import std/threadpool
proc processLine(line: string) =
discard "do some heavy lifting here"
@@ -1437,7 +1437,7 @@ with the ``^`` operator is **blocking**. However, one can use ``blockUntilAny``
wait on multiple flow variables at the same time:
.. code-block:: nim
import threadpool, ...
import std/threadpool, ...
# wait until 2 out of 3 servers received the update:
proc main =
@@ -1466,7 +1466,7 @@ Example:
:test: "nim c --threads:on $1"
# Compute PI in an inefficient way
import strutils, math, threadpool
import std/[strutils, math, threadpool]
{.experimental: "parallel".}
proc term(k: float): float = 4 * math.pow(-1, k) / (2*k + 1)

View File

@@ -228,7 +228,7 @@ See the following (incomplete) example:
.. code-block:: nim
import distros
import std/distros
# Architectures.
if defined(amd64):

View File

@@ -227,7 +227,7 @@ JavaScript tests:
targets: "js"
"""
when defined(js):
import jsconsole
import std/jsconsole
console.log("My Frontend Project")
Compile-time tests:

View File

@@ -310,7 +310,7 @@ For integers or other ordinal types value ranges are also possible:
.. code-block:: nim
# this statement will be explained later:
from strutils import parseInt
from std/strutils import parseInt
echo "A number please: "
let n = parseInt(readLine(stdin))
@@ -1607,7 +1607,7 @@ variables! For example:
.. code-block:: nim
:test: "nim c $1"
import os
import std/os
let
path = "usr/local/nimc.html"

View File

@@ -182,7 +182,7 @@ for any type:
.. code-block:: nim
:test: "nim c $1"
import strutils
import std/strutils
echo "abc".len # is the same as echo len("abc")
echo "abc".toUpperAscii()
@@ -196,7 +196,7 @@ So "pure object oriented" code is easy to write:
.. code-block:: nim
:test: "nim c $1"
import strutils, sequtils
import std/[strutils, sequtils]
stdout.writeLine("Give a list of numbers (separated by spaces): ")
stdout.write(stdin.readLine.splitWhitespace.map(parseInt).max.`$`)
@@ -375,7 +375,7 @@ The ``try`` statement handles exceptions:
.. code-block:: nim
:test: "nim c $1"
from strutils import parseInt
from std/strutils import parseInt
# read the first two lines of a text file that should contain numbers
# and tries to add them
@@ -649,7 +649,7 @@ Example: Lifting Procs
.. code-block:: nim
:test: "nim c $1"
import math
import std/math
template liftScalarProc(fname) =
## Lift a proc taking one scalar parameter and returning a

View File

@@ -91,7 +91,7 @@ but in the macro body ``arg`` is just like a normal parameter of type
.. code-block:: nim
import macros
import std/macros
macro myMacro(arg: static[int]): untyped =
echo arg # just an int (7), not ``NimNode``
@@ -193,7 +193,7 @@ them into the tree.
.. code-block:: nim
:test: "nim c $1"
import macros
import std/macros
type
MyType = object
@@ -232,7 +232,7 @@ correct argument should look like.
.. code-block:: nim
:test: "nim c $1"
import macros
import std/macros
macro myAssert(arg: untyped): untyped =
echo arg.treeRepr
@@ -258,7 +258,7 @@ written.
.. code-block:: nim
:test: "nim c $1"
import macros
import std/macros
macro myAssert(arg: untyped): untyped =
# all node kind identifiers are prefixed with "nnk"