mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
Nimrod renamed to Nim
This commit is contained in:
@@ -261,7 +261,7 @@ proc getAst*(macroOrTemplate: expr): PNimrodNode {.magic: "ExpandToAst", noSideE
|
||||
## Obtains the AST nodes returned from a macro or template invocation.
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## macro FooMacro() =
|
||||
## var ast = getAst(BarTemplate())
|
||||
@@ -278,7 +278,7 @@ proc quote*(bl: stmt, op = "``"): PNimrodNode {.magic: "QuoteAst", noSideEffect.
|
||||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## macro check(ex: expr): stmt =
|
||||
## # this is a simplified version of the check macro from the
|
||||
@@ -422,7 +422,7 @@ proc lispRepr*(n: PNimrodNode): string {.compileTime.} =
|
||||
add(result, ")")
|
||||
|
||||
macro dumpTree*(s: stmt): stmt {.immediate.} = echo s.treeRepr
|
||||
## Accepts a block of nimrod code and prints the parsed abstract syntax
|
||||
## Accepts a block of nim code and prints the parsed abstract syntax
|
||||
## tree using the `toTree` function. Printing is done *at compile time*.
|
||||
##
|
||||
## You can use this as a tool to explore the Nimrod's abstract syntax
|
||||
@@ -430,7 +430,7 @@ macro dumpTree*(s: stmt): stmt {.immediate.} = echo s.treeRepr
|
||||
## a certain expression/statement.
|
||||
|
||||
macro dumpLisp*(s: stmt): stmt {.immediate.} = echo s.lispRepr
|
||||
## Accepts a block of nimrod code and prints the parsed abstract syntax
|
||||
## Accepts a block of nim code and prints the parsed abstract syntax
|
||||
## tree using the `toLisp` function. Printing is done *at compile time*.
|
||||
##
|
||||
## See `dumpTree`.
|
||||
@@ -489,7 +489,7 @@ proc newIdentDefs*(name, kind: PNimrodNode;
|
||||
## ``let`` or ``var`` blocks may have an empty ``kind`` node if the
|
||||
## identifier is being assigned a value. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## var varSection = newNimNode(nnkVarSection).add(
|
||||
## newIdentDefs(ident("a"), ident("string")),
|
||||
@@ -501,7 +501,7 @@ proc newIdentDefs*(name, kind: PNimrodNode;
|
||||
## If you need to create multiple identifiers you need to use the lower level
|
||||
## ``newNimNode``:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## result = newNimNode(nnkIdentDefs).add(
|
||||
## ident("a"), ident("b"), ident("c"), ident("string"),
|
||||
@@ -549,7 +549,7 @@ proc newIfStmt*(branches: varargs[tuple[cond, body: PNimrodNode]]):
|
||||
PNimrodNode {.compiletime.} =
|
||||
## Constructor for ``if`` statements.
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## newIfStmt(
|
||||
## (Ident, StmtList),
|
||||
@@ -643,7 +643,7 @@ template findChild*(n: PNimrodNode; cond: expr): PNimrodNode {.
|
||||
immediate, dirty.} =
|
||||
## Find the first child node matching condition (or nil).
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## var res = findChild(n, it.kind == nnkPostfix and
|
||||
## it.basename.ident == !"foo")
|
||||
block:
|
||||
@@ -738,11 +738,11 @@ proc addIdentIfAbsent*(dest: PNimrodNode, ident: string) {.compiletime.} =
|
||||
|
||||
when not defined(booting):
|
||||
template emit*(e: static[string]): stmt =
|
||||
## accepts a single string argument and treats it as nimrod code
|
||||
## accepts a single string argument and treats it as nim code
|
||||
## that should be inserted verbatim in the program
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## emit("echo " & '"' & "hello world".toUpper & '"')
|
||||
##
|
||||
macro payload: stmt {.gensym.} =
|
||||
|
||||
@@ -50,7 +50,7 @@ type
|
||||
akUInt32 = 43, ## any represents an unsigned int32
|
||||
akUInt64 = 44, ## any represents an unsigned int64
|
||||
|
||||
TAny* = object {.pure.} ## can represent any nimrod value; NOTE: the wrapped
|
||||
TAny* = object {.pure.} ## can represent any nim value; NOTE: the wrapped
|
||||
## value can be modified with its wrapper! This means
|
||||
## that ``TAny`` keeps a non-traced pointer to its
|
||||
## wrapped value and **must not** live longer than
|
||||
|
||||
@@ -186,7 +186,7 @@ proc open*(connection, user, password, database: string): TDbConn {.
|
||||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## con = Open("", "", "", "host=localhost port=5432 dbname=mydb")
|
||||
##
|
||||
@@ -194,7 +194,7 @@ proc open*(connection, user, password, database: string): TDbConn {.
|
||||
## for more information.
|
||||
##
|
||||
## Note that the connection parameter is not used but exists to maintain
|
||||
## the nimrod db api.
|
||||
## the nim db api.
|
||||
result = PQsetdbLogin(nil, nil, nil, nil, database, user, password)
|
||||
if PQStatus(result) != CONNECTION_OK: dbError(result) # result = nil
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ template `=~` *(s: string, pattern: TRegex): expr =
|
||||
## This calls ``match`` with an implicit declared ``matches`` array that
|
||||
## can be used in the scope of the ``=~`` call:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## if line =~ re"\s*(\w+)\s*\=\s*(\w+)":
|
||||
## # matches a key=value pair:
|
||||
@@ -271,12 +271,12 @@ proc replace*(s: string, sub: TRegex, by = ""): string =
|
||||
## Replaces `sub` in `s` by the string `by`. Captures cannot be
|
||||
## accessed in `by`. Examples:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## "var1=key; var2=key2".replace(re"(\w+)'='(\w+)")
|
||||
##
|
||||
## Results in:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## "; "
|
||||
result = ""
|
||||
@@ -293,12 +293,12 @@ proc replacef*(s: string, sub: TRegex, by: string): string =
|
||||
## Replaces `sub` in `s` by the string `by`. Captures can be accessed in `by`
|
||||
## with the notation ``$i`` and ``$#`` (see strutils.`%`). Examples:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## "var1=key; var2=key2".replacef(re"(\w+)'='(\w+)", "$1<-$2$2")
|
||||
##
|
||||
## Results in:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## "var1<-keykey; val2<-key2key2"
|
||||
result = ""
|
||||
@@ -360,13 +360,13 @@ iterator split*(s: string, sep: TRegex): string =
|
||||
## Substrings are separated by the regular expression `sep`.
|
||||
## Examples:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## for word in split("00232this02939is39an22example111", re"\d+"):
|
||||
## writeln(stdout, word)
|
||||
##
|
||||
## Results in:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## "this"
|
||||
## "is"
|
||||
## "an"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#
|
||||
|
||||
## This module provides an easy to use sockets-style
|
||||
## nimrod interface to the OpenSSL library.
|
||||
## nim interface to the OpenSSL library.
|
||||
|
||||
{.deprecated.}
|
||||
|
||||
|
||||
@@ -59,5 +59,5 @@ proc URLretrieveString*(url: string): TaintedString =
|
||||
result = stream.data.TaintedString
|
||||
|
||||
when isMainModule:
|
||||
echo URLretrieveString("http://nimrod-code.org/")
|
||||
echo URLretrieveString("http://nim-code.org/")
|
||||
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
## This is an include file that simply imports common modules for your
|
||||
## convenience:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## include prelude
|
||||
##
|
||||
## Same as:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## import os, strutils, times, parseutils, parseopt, hashes, tables, sets
|
||||
|
||||
import os, strutils, times, parseutils, parseopt, hashes, tables, sets
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## var
|
||||
## a: TActorPool[int, void]
|
||||
|
||||
@@ -159,7 +159,7 @@ proc sort*[T](a: var openArray[T],
|
||||
## sensible default argument for ``cmp``, so you have to provide one
|
||||
## of your own. However, the ``system.cmp`` procs can be used:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## sort(myIntArray, system.cmp[int])
|
||||
##
|
||||
@@ -170,7 +170,7 @@ proc sort*[T](a: var openArray[T],
|
||||
## You can inline adhoc comparison procs with the `do notation
|
||||
## <manual.html#do-notation>`_. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## people.sort do (x, y: Person) -> int:
|
||||
## result = cmp(x.surname, y.surname)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
##
|
||||
## The following example demonstrates a simple chat server.
|
||||
##
|
||||
## .. code-block::nimrod
|
||||
## .. code-block::nim
|
||||
##
|
||||
## import asyncnet, asyncdispatch
|
||||
##
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nimrod c -t:-march=i686 --cpu:amd64 --threads:on -d:release lockfreehash.nim
|
||||
#nim c -t:-march=i686 --cpu:amd64 --threads:on -d:release lockfreehash.nim
|
||||
|
||||
import unsigned, math, hashes
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ proc createProcType(p, b: PNimrodNode): PNimrodNode {.compileTime.} =
|
||||
macro `=>`*(p, b: expr): expr {.immediate.} =
|
||||
## Syntax sugar for anonymous procedures.
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## proc passTwoAndTwo(f: (int, int) -> int): int =
|
||||
## f(2, 2)
|
||||
@@ -104,7 +104,7 @@ macro `=>`*(p, b: expr): expr {.immediate.} =
|
||||
macro `->`*(p, b: expr): expr {.immediate.} =
|
||||
## Syntax sugar for procedure types.
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## proc pass2(f: (float, float) -> float): float =
|
||||
## f(2, 2)
|
||||
|
||||
@@ -656,17 +656,17 @@ when isMainModule:
|
||||
resp = await client.request("http://picheta.me/aboutme.html")
|
||||
echo("Got response: ", resp.status)
|
||||
|
||||
resp = await client.request("http://nimrod-lang.org/")
|
||||
resp = await client.request("http://nim-lang.org/")
|
||||
echo("Got response: ", resp.status)
|
||||
|
||||
resp = await client.request("http://nimrod-lang.org/download.html")
|
||||
resp = await client.request("http://nim-lang.org/download.html")
|
||||
echo("Got response: ", resp.status)
|
||||
|
||||
asyncCheck main()
|
||||
runForever()
|
||||
|
||||
else:
|
||||
#downloadFile("http://force7.de/nimrod/index.html", "nimrodindex.html")
|
||||
#downloadFile("http://force7.de/nim/index.html", "nimindex.html")
|
||||
#downloadFile("http://www.httpwatch.com/", "ChunkTest.html")
|
||||
#downloadFile("http://validator.w3.org/check?uri=http%3A%2F%2Fgoogle.com",
|
||||
# "validator.html")
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## import strutils, sockets, httpserver
|
||||
##
|
||||
## var counter = 0
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
##
|
||||
## Usage example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## let
|
||||
## small_json = """{"test": 1.3, "key2": true}"""
|
||||
## jobj = parseJson(small_json)
|
||||
@@ -26,7 +26,7 @@
|
||||
##
|
||||
## Results in:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## 1.3000000000000000e+00
|
||||
## true
|
||||
|
||||
@@ -514,12 +514,12 @@ proc joinPath*(head, tail: string): string {.
|
||||
##
|
||||
## For example on Unix:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## joinPath("usr", "lib")
|
||||
##
|
||||
## results in:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## "usr/lib"
|
||||
##
|
||||
## If head is the empty string, tail is returned. If tail is the empty
|
||||
@@ -528,7 +528,7 @@ proc joinPath*(head, tail: string): string {.
|
||||
## path separators not located on boundaries won't be modified. More
|
||||
## examples on Unix:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## assert joinPath("usr", "") == "usr/"
|
||||
## assert joinPath("", "lib") == "lib"
|
||||
## assert joinPath("", "/lib") == "/lib"
|
||||
@@ -560,7 +560,7 @@ proc `/` * (head, tail: string): string {.noSideEffect.} =
|
||||
##
|
||||
## Here are some examples for Unix:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## assert "usr" / "" == "usr/"
|
||||
## assert "" / "lib" == "lib"
|
||||
## assert "" / "/lib" == "/lib"
|
||||
@@ -574,7 +574,7 @@ proc splitPath*(path: string): tuple[head, tail: string] {.
|
||||
##
|
||||
## Examples:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## splitPath("usr/local/bin") -> ("usr/local", "bin")
|
||||
## splitPath("usr/local/bin/") -> ("usr/local/bin", "")
|
||||
## splitPath("bin") -> ("", "bin")
|
||||
@@ -674,10 +674,10 @@ proc splitFile*(path: string): tuple[dir, name, ext: string] {.
|
||||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## var (dir, name, ext) = splitFile("usr/local/nimrodc.html")
|
||||
## .. code-block:: nim
|
||||
## var (dir, name, ext) = splitFile("usr/local/nimc.html")
|
||||
## assert dir == "usr/local"
|
||||
## assert name == "nimrodc"
|
||||
## assert name == "nimc"
|
||||
## assert ext == ".html"
|
||||
##
|
||||
## If `path` has no extension, `ext` is the empty string.
|
||||
@@ -1579,7 +1579,7 @@ proc inclFilePermissions*(filename: string,
|
||||
rtl, extern: "nos$1", tags: [ReadDirEffect, WriteDirEffect].} =
|
||||
## a convenience procedure for:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## setFilePermissions(filename, getFilePermissions(filename)+permissions)
|
||||
setFilePermissions(filename, getFilePermissions(filename)+permissions)
|
||||
|
||||
@@ -1588,7 +1588,7 @@ proc exclFilePermissions*(filename: string,
|
||||
rtl, extern: "nos$1", tags: [ReadDirEffect, WriteDirEffect].} =
|
||||
## a convenience procedure for:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## setFilePermissions(filename, getFilePermissions(filename)-permissions)
|
||||
setFilePermissions(filename, getFilePermissions(filename)-permissions)
|
||||
|
||||
@@ -1627,7 +1627,7 @@ when defined(nimdoc):
|
||||
## can test for its availability with `declared() <system.html#declared>`_.
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## when declared(paramCount):
|
||||
## # Use paramCount() here
|
||||
## else:
|
||||
@@ -1650,7 +1650,7 @@ when defined(nimdoc):
|
||||
## can test for its availability with `declared() <system.html#declared>`_.
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## when declared(paramStr):
|
||||
## # Use paramStr() here
|
||||
## else:
|
||||
@@ -1703,7 +1703,7 @@ when declared(paramCount) or defined(nimdoc):
|
||||
## can test for its availability with `declared() <system.html#declared>`_.
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## when declared(commandLineParams):
|
||||
## # Use commandLineParams() here
|
||||
## else:
|
||||
@@ -1858,7 +1858,7 @@ proc expandTilde*(path: string): string =
|
||||
## The behaviour of this proc is the same on the Windows platform despite not
|
||||
## having this convention. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## let configFile = expandTilde("~" / "appname.cfg")
|
||||
## echo configFile
|
||||
## # --> C:\Users\amber\appname.cfg
|
||||
@@ -1889,7 +1889,7 @@ type
|
||||
creationTime*: Time # Time file was created. Not supported on all systems!
|
||||
|
||||
template rawToFormalFileInfo(rawInfo, formalInfo): expr =
|
||||
## Transforms the native file info structure into the one nimrod uses.
|
||||
## Transforms the native file info structure into the one nim uses.
|
||||
## 'rawInfo' is either a 'TBY_HANDLE_FILE_INFORMATION' structure on Windows,
|
||||
## or a 'TStat' structure on posix
|
||||
when defined(Windows):
|
||||
|
||||
@@ -771,7 +771,7 @@ elif not defined(useNimRtl):
|
||||
|
||||
proc startProcessAfterFork(data: ptr TStartProcessData) =
|
||||
# Warning: no GC here!
|
||||
# Or anything that touches global structures - all called nimrod procs
|
||||
# Or anything that touches global structures - all called nim procs
|
||||
# must be marked with stackTrace:off. Inspect C code after making changes.
|
||||
if not data.optionPoParentStreams:
|
||||
discard close(data.pStdin[writeIdx])
|
||||
|
||||
@@ -132,7 +132,7 @@ when declared(initOptParser):
|
||||
## This is an convenience iterator for iterating over the command line.
|
||||
## This uses the TOptParser object. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## var
|
||||
## filename = ""
|
||||
## for kind, key, val in getopt():
|
||||
|
||||
@@ -348,13 +348,13 @@ iterator interpolatedFragments*(s: string): tuple[kind: InterpolatedKind,
|
||||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## for k, v in interpolatedFragments(" $this is ${an example} $$"):
|
||||
## echo "(", k, ", \"", v, "\")"
|
||||
##
|
||||
## Results in:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## (ikString, " ")
|
||||
## (ikExpr, "this")
|
||||
## (ikString, " is ")
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
## XML parser to accomplish a simple task: To determine the title of an HTML
|
||||
## document.
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## :file: examples/htmltitle.nim
|
||||
##
|
||||
##
|
||||
@@ -44,7 +44,7 @@
|
||||
## XML parser to accomplish another simple task: To determine all the links
|
||||
## an HTML document contains.
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## :file: examples/htmlrefs.nim
|
||||
##
|
||||
|
||||
|
||||
@@ -298,7 +298,7 @@ when not defined(JS):
|
||||
## To generate useful timing values, take the difference between
|
||||
## the results of two ``cpuTime`` calls:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## var t0 = cpuTime()
|
||||
## doWork()
|
||||
## echo "CPU time [s] ", cpuTime() - t0
|
||||
|
||||
@@ -275,12 +275,12 @@ proc xmlConstructor(e: PNimrodNode): PNimrodNode {.compileTime.} =
|
||||
macro `<>`*(x: expr): expr {.immediate.} =
|
||||
## Constructor macro for XML. Example usage:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## <>a(href="http://nimrod-code.org", newText("Nim rules."))
|
||||
## .. code-block:: nim
|
||||
## <>a(href="http://nim-code.org", newText("Nim rules."))
|
||||
##
|
||||
## Produces an XML tree for::
|
||||
##
|
||||
## <a href="http://nimrod-code.org">Nim rules.</a>
|
||||
## <a href="http://nim-code.org">Nim rules.</a>
|
||||
##
|
||||
let x = callsite()
|
||||
result = xmlConstructor(x)
|
||||
@@ -339,5 +339,5 @@ proc findAll*(n: XmlNode, tag: string): seq[XmlNode] =
|
||||
findAll(n, tag, result)
|
||||
|
||||
when isMainModule:
|
||||
assert """<a href="http://nimrod-code.org">Nim rules.</a>""" ==
|
||||
$(<>a(href="http://nimrod-code.org", newText("Nim rules.")))
|
||||
assert """<a href="http://nim-code.org">Nim rules.</a>""" ==
|
||||
$(<>a(href="http://nim-code.org", newText("Nim rules.")))
|
||||
|
||||
@@ -100,7 +100,7 @@ proc defined*(x: expr): bool {.magic: "Defined", noSideEffect.}
|
||||
## Special compile-time procedure that checks whether `x` is
|
||||
## defined.
|
||||
## `x` is an external symbol introduced through the compiler's
|
||||
## `-d:x switch <nimrodc.html#compile-time-symbols>`_ to enable build time
|
||||
## `-d:x switch <nimc.html#compile-time-symbols>`_ to enable build time
|
||||
## conditionals:
|
||||
##
|
||||
## .. code-block:: Nim
|
||||
@@ -509,7 +509,7 @@ proc sizeof*[T](x: T): Natural {.magic: "SizeOf", noSideEffect.}
|
||||
proc `<`*[T](x: Ordinal[T]): T {.magic: "UnaryLt", noSideEffect.}
|
||||
## unary ``<`` that can be used for nice looking excluding ranges:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## for i in 0 .. <10: echo i
|
||||
##
|
||||
## Semantically this is the same as ``pred``.
|
||||
@@ -544,7 +544,7 @@ proc newSeq*[T](s: var seq[T], len: int) {.magic: "NewSeq", noSideEffect.}
|
||||
## ``nil``. After the creation of the sequence you should assign entries to
|
||||
## the sequence instead of adding them. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## var inputStrings : seq[string]
|
||||
## newSeq(inputStrings, 3)
|
||||
## inputStrings[0] = "The fourth"
|
||||
@@ -560,7 +560,7 @@ proc newSeq*[T](len = 0): seq[T] =
|
||||
## ``nil``. After the creation of the sequence you should assign entries to
|
||||
## the sequence instead of adding them. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## var inputStrings = newSeq[string](3)
|
||||
## inputStrings[0] = "The fourth"
|
||||
## inputStrings[1] = "assignment"
|
||||
@@ -1058,7 +1058,7 @@ proc compileOption*(option: string): bool {.
|
||||
magic: "CompileOption", noSideEffect.}
|
||||
## can be used to determine an on|off compile-time option. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## when compileOption("floatchecks"):
|
||||
## echo "compiled with floating point NaN and Inf checks"
|
||||
|
||||
@@ -1066,7 +1066,7 @@ proc compileOption*(option, arg: string): bool {.
|
||||
magic: "CompileOptionArg", noSideEffect.}
|
||||
## can be used to determine an enum compile-time option. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## when compileOption("opt", "size") and compileOption("gc", "boehm"):
|
||||
## echo "compiled with optimization for size and uses Boehm's GC"
|
||||
|
||||
@@ -1123,7 +1123,7 @@ proc quit*(errorcode: int = QuitSuccess) {.
|
||||
## procedures. It does *not* call the garbage collector to free all the
|
||||
## memory, unless a quit procedure calls ``GC_collect``.
|
||||
##
|
||||
## The proc ``quit(QuitSuccess)`` is called implicitly when your nimrod
|
||||
## The proc ``quit(QuitSuccess)`` is called implicitly when your nim
|
||||
## program finishes without incident. A raised unhandled exception is
|
||||
## equivalent to calling ``quit(QuitFailure)``.
|
||||
##
|
||||
@@ -1840,7 +1840,7 @@ proc map*[T, S](data: openArray[T], op: proc (x: T): S {.closure.}): seq[S] =
|
||||
## Since the input is not modified you can use this version of ``map`` to
|
||||
## transform the type of the elements in the input sequence. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## let
|
||||
## a = @[1, 2, 3, 4]
|
||||
## b = map(a, proc(x: int): string = $x)
|
||||
@@ -1854,7 +1854,7 @@ proc map*[T](data: var openArray[T], op: proc (x: var T) {.closure.}) =
|
||||
## Note that this version of ``map`` requires your input and output types to
|
||||
## be the same, since they are modified in-place. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## var a = @["1", "2", "3", "4"]
|
||||
## echo repr(a)
|
||||
## # --> ["1", "2", "3", "4"]
|
||||
@@ -1945,7 +1945,7 @@ proc `$`*[T: tuple|object](x: T): string =
|
||||
## generic ``$`` operator for tuples that is lifted from the components
|
||||
## of `x`. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## $(23, 45) == "(23, 45)"
|
||||
## $() == "()"
|
||||
result = "("
|
||||
@@ -1971,7 +1971,7 @@ proc `$`*[T](x: set[T]): string =
|
||||
## generic ``$`` operator for sets that is lifted from the components
|
||||
## of `x`. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## ${23, 45} == "{23, 45}"
|
||||
collectionToString(x, "{", "}")
|
||||
|
||||
@@ -1979,7 +1979,7 @@ proc `$`*[T](x: seq[T]): string =
|
||||
## generic ``$`` operator for seqs that is lifted from the components
|
||||
## of `x`. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## $(@[23, 45]) == "@[23, 45]"
|
||||
collectionToString(x, "@[", "]")
|
||||
|
||||
@@ -2078,7 +2078,7 @@ var
|
||||
## writes an error message and terminates the program. `outOfMemHook` can
|
||||
## be used to raise an exception in case of OOM like so:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## var gOutOfMem: ref EOutOfMemory
|
||||
## new(gOutOfMem) # need to be allocated *before* OOM really happened!
|
||||
@@ -2576,7 +2576,7 @@ when not defined(JS): #and not defined(NimrodVM):
|
||||
## If the file does not exist `EIO` is raised. The trailing newline
|
||||
## character(s) are removed from the iterated lines. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## import strutils
|
||||
##
|
||||
## proc transformLetters(filename: string) =
|
||||
@@ -2595,7 +2595,7 @@ when not defined(JS): #and not defined(NimrodVM):
|
||||
## The trailing newline character(s) are removed from the iterated lines.
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## proc countZeros(filename: File): tuple[lines, zeros: int] =
|
||||
## for line in filename.lines:
|
||||
## for letter in line:
|
||||
@@ -2645,7 +2645,7 @@ when not defined(JS): #and not defined(NimrodVM):
|
||||
## platforms this can help the processor predict better which branch is
|
||||
## going to be run. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## for value in inputValues:
|
||||
## if likely(value <= 100):
|
||||
## process(value)
|
||||
@@ -2659,7 +2659,7 @@ when not defined(JS): #and not defined(NimrodVM):
|
||||
## platforms this can help the processor predict better which branch is
|
||||
## going to be run. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## for value in inputValues:
|
||||
## if unlikely(value > 100):
|
||||
## echo "Value too big!"
|
||||
@@ -2766,7 +2766,7 @@ when hostOS != "standalone":
|
||||
## ``b.len`` is not exactly the number of elements that are referred to
|
||||
## by `x`, a `splice`:idx: is performed:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## var s = "abcdef"
|
||||
## s[1 .. -2] = "xyz"
|
||||
## assert s == "axyzf"
|
||||
@@ -2843,7 +2843,7 @@ proc slurp*(filename: string): string {.magic: "Slurp".}
|
||||
proc staticRead*(filename: string): string {.magic: "Slurp".}
|
||||
## Compile-time ``readFile`` proc for easy `resource`:idx: embedding:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## const myResource = staticRead"mydatafile.bin"
|
||||
##
|
||||
## ``slurp`` is an alias for ``staticRead``.
|
||||
@@ -2858,13 +2858,13 @@ proc staticExec*(command: string, input = ""): string {.
|
||||
## if `input` is not an empty string, it will be passed as a standard input
|
||||
## to the executed program.
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## const buildInfo = "Revision " & staticExec("git rev-parse HEAD") &
|
||||
## "\nCompiled on " & staticExec("uname -v")
|
||||
##
|
||||
## ``gorge`` is an alias for ``staticExec``. Note that you can use this proc
|
||||
## inside a pragma like `passC <nimrodc.html#passc-pragma>`_ or `passL
|
||||
## <nimrodc.html#passl-pragma>`_.
|
||||
## inside a pragma like `passC <nimc.html#passc-pragma>`_ or `passL
|
||||
## <nimc.html#passl-pragma>`_.
|
||||
|
||||
proc `+=`*[T: SomeOrdinal|uint|uint64](x: var T, y: T) {.magic: "Inc", noSideEffect.}
|
||||
## Increments an ordinal
|
||||
@@ -2906,7 +2906,7 @@ proc instantiationInfo*(index = -1, fullPaths = false): tuple[
|
||||
## to retrieve information about the current filename and line number.
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## import strutils
|
||||
##
|
||||
## template testException(exception, code: expr): stmt =
|
||||
@@ -2951,7 +2951,7 @@ template assert*(cond: bool, msg = "") =
|
||||
## raises an ``EAssertionFailure`` exception. However, the compiler may not
|
||||
## generate any code at all for ``assert`` if it is advised to do so through
|
||||
## the ``-d:release`` or ``--assertions:off`` `command line switches
|
||||
## <nimrodc.html#command-line-switches>`_.
|
||||
## <nimc.html#command-line-switches>`_.
|
||||
##
|
||||
## Use ``assert`` for debugging purposes only.
|
||||
bind instantiationInfo
|
||||
@@ -2994,7 +2994,7 @@ template onFailedAssert*(msg: expr, code: stmt): stmt {.dirty, immediate.} =
|
||||
## statements following `onFailedAssert` in the current lexical scope.
|
||||
## Can be defined multiple times in a single function.
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
##
|
||||
## proc example(x: int): TErrorCode =
|
||||
## onFailedAssert(msg):
|
||||
@@ -3089,7 +3089,7 @@ proc locals*(): RootObj {.magic: "Locals", noSideEffect.} =
|
||||
## the official signature says, the return type is not ``TObject`` but a
|
||||
## tuple of a structure that depends on the current scope. Example:
|
||||
##
|
||||
## .. code-block:: nimrod
|
||||
## .. code-block:: nim
|
||||
## proc testLocals() =
|
||||
## var
|
||||
## a = "something"
|
||||
|
||||
Reference in New Issue
Block a user