mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 09:54:49 +00:00
@@ -28,7 +28,7 @@ The parser uses a stack of indentation levels: the stack consists of integers
|
||||
counting the spaces. The indentation information is queried at strategic
|
||||
places in the parser but ignored otherwise: The pseudo terminal ``IND{>}``
|
||||
denotes an indentation that consists of more spaces than the entry at the top
|
||||
of the stack; IND{=} an indentation that has the same number of spaces. ``DED``
|
||||
of the stack; ``IND{=}`` an indentation that has the same number of spaces. ``DED``
|
||||
is another pseudo terminal that describes the *action* of popping a value
|
||||
from the stack, ``IND{>}`` then implies to push onto the stack.
|
||||
|
||||
@@ -399,7 +399,7 @@ These keywords are also operators:
|
||||
`=`:tok:, `:`:tok:, `::`:tok: are not available as general operators; they
|
||||
are used for other notational purposes.
|
||||
|
||||
``*:`` is as a special case the two tokens `*`:tok: and `:`:tok:
|
||||
``*:`` is as a special case treated as the two tokens `*`:tok: and `:`:tok:
|
||||
(to support ``var v*: T``).
|
||||
|
||||
|
||||
|
||||
@@ -61,14 +61,14 @@ Calling a procedure can be done in many different ways:
|
||||
.. code-block:: nim
|
||||
proc callme(x, y: int, s: string = "", c: char, b: bool = false) = ...
|
||||
|
||||
# call with positional arguments # parameter bindings:
|
||||
callme(0, 1, "abc", '\t', true) # (x=0, y=1, s="abc", c='\t', b=true)
|
||||
# call with positional arguments # parameter bindings:
|
||||
callme(0, 1, "abc", '\t', true) # (x=0, y=1, s="abc", c='\t', b=true)
|
||||
# call with named and positional arguments:
|
||||
callme(y=1, x=0, "abd", '\t') # (x=0, y=1, s="abd", c='\t', b=false)
|
||||
callme(y=1, x=0, "abd", '\t') # (x=0, y=1, s="abd", c='\t', b=false)
|
||||
# call with named arguments (order is not relevant):
|
||||
callme(c='\t', y=1, x=0) # (x=0, y=1, s="", c='\t', b=false)
|
||||
callme(c='\t', y=1, x=0) # (x=0, y=1, s="", c='\t', b=false)
|
||||
# call as a command statement: no () needed:
|
||||
callme 0, 1, "abc", '\t'
|
||||
callme 0, 1, "abc", '\t' # (x=0, y=1, s="abc", c='\t', b=false)
|
||||
|
||||
A procedure may call itself recursively.
|
||||
|
||||
|
||||
@@ -462,10 +462,10 @@ While statement
|
||||
Example:
|
||||
|
||||
.. code-block:: nim
|
||||
echo "Please tell me your password: \n"
|
||||
echo "Please tell me your password:"
|
||||
var pw = readLine(stdin)
|
||||
while pw != "12345":
|
||||
echo "Wrong password! Next try: \n"
|
||||
echo "Wrong password! Next try:"
|
||||
pw = readLine(stdin)
|
||||
|
||||
|
||||
|
||||
@@ -62,7 +62,8 @@ Precedence level Operators First charact
|
||||
================ =============================================== ================== ===============
|
||||
|
||||
|
||||
Whether an operator is used a prefix operator is also affected by preceeding whitespace (this parsing change was introduced with version 0.13.0):
|
||||
Whether an operator is used a prefix operator is also affected by preceding
|
||||
whitespace (this parsing change was introduced with version 0.13.0):
|
||||
|
||||
.. code-block:: nim
|
||||
echo $foo
|
||||
|
||||
@@ -406,11 +406,11 @@ builtin can be used for that:
|
||||
|
||||
macro debug(n: varargs[typed]): untyped =
|
||||
result = newNimNode(nnkStmtList, n)
|
||||
for i in 0..n.len-1:
|
||||
for x in n:
|
||||
# we can bind symbols in scope via 'bindSym':
|
||||
add(result, newCall(bindSym"write", bindSym"stdout", toStrLit(n[i])))
|
||||
add(result, newCall(bindSym"write", bindSym"stdout", toStrLit(x)))
|
||||
add(result, newCall(bindSym"write", bindSym"stdout", newStrLitNode(": ")))
|
||||
add(result, newCall(bindSym"writeLine", bindSym"stdout", n[i]))
|
||||
add(result, newCall(bindSym"writeLine", bindSym"stdout", x))
|
||||
|
||||
var
|
||||
a: array [0..10, int]
|
||||
|
||||
@@ -13,7 +13,7 @@ Example:
|
||||
Sym = object # a symbol
|
||||
name: string # the symbol's name
|
||||
line: int # the line the symbol was declared in
|
||||
code: Node # the symbol's abstract syntax tree
|
||||
code: Node # the symbol's abstract syntax tree
|
||||
|
||||
A type section begins with the ``type`` keyword. It contains multiple
|
||||
type definitions. A type definition binds a type to a name. Type definitions
|
||||
|
||||
@@ -227,8 +227,8 @@ floating pointer values at compile time; this means expressions like
|
||||
Boolean type
|
||||
------------
|
||||
The boolean type is named `bool`:idx: in Nim and can be one of the two
|
||||
pre-defined values ``true`` and ``false``. Conditions in while,
|
||||
if, elif, when statements need to be of type bool.
|
||||
pre-defined values ``true`` and ``false``. Conditions in ``while``,
|
||||
``if``, ``elif``, ``when``-statements need to be of type ``bool``.
|
||||
|
||||
This condition holds::
|
||||
|
||||
@@ -609,7 +609,7 @@ is similar to the ``instanceof`` operator in Java.
|
||||
age: int # no * means that the field is hidden
|
||||
|
||||
Student = ref object of Person # a student is a person
|
||||
id: int # with an id field
|
||||
id: int # with an id field
|
||||
|
||||
var
|
||||
student: Student
|
||||
@@ -1262,4 +1262,4 @@ Is the same as:
|
||||
|
||||
However later versions of the language might change this to mean "infer the
|
||||
parameters' types from the body". Then the above ``foo`` would be rejected as
|
||||
the parameters' types can not be infered from an empty ``discard`` statement.
|
||||
the parameters' types can not be inferred from an empty ``discard`` statement.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
The set type models the mathematical notion of a set. The set's
|
||||
basetype can only be an ordinal type of a certain size, namely:
|
||||
The set type models the mathematical notion of a set. The set's basetype can
|
||||
only be an ordinal type of a certain size, namely:
|
||||
* ``int8``-``int16``
|
||||
* ``uint8``/``byte``-``uint16``
|
||||
* ``char``
|
||||
|
||||
@@ -1521,7 +1521,7 @@ type # these work for most platforms:
|
||||
## This is the same as the type ``double`` in *C*.
|
||||
clongdouble* {.importc: "long double", nodecl.} = BiggestFloat
|
||||
## This is the same as the type ``long double`` in *C*.
|
||||
## This C type is not supported by Nim's code generator
|
||||
## This C type is not supported by Nim's code generator.
|
||||
|
||||
cuchar* {.importc: "unsigned char", nodecl.} = char
|
||||
## This is the same as the type ``unsigned char`` in *C*.
|
||||
@@ -2653,12 +2653,11 @@ when not defined(JS): #and not defined(nimscript):
|
||||
|
||||
when defined(nimscript):
|
||||
proc readFile*(filename: string): string {.tags: [ReadIOEffect], benign.}
|
||||
## Opens a file named `filename` for reading.
|
||||
##
|
||||
## Then calls `readAll <#readAll>`_ and closes the file afterwards.
|
||||
## Returns the string. Raises an IO exception in case of an error. If
|
||||
## you need to call this inside a compile time macro you can use
|
||||
## `staticRead <#staticRead>`_.
|
||||
## Opens a file named `filename` for reading, calls `readAll
|
||||
## <#readAll>`_ and closes the file afterwards. Returns the string.
|
||||
## Raises an IO exception in case of an error. If # you need to call
|
||||
## this inside a compile time macro you can use `staticRead
|
||||
## <#staticRead>`_.
|
||||
|
||||
proc writeFile*(filename, content: string) {.tags: [WriteIOEffect], benign.}
|
||||
## Opens a file named `filename` for writing. Then writes the
|
||||
|
||||
Reference in New Issue
Block a user