diff options
author | Jjp137 <Jjp137@users.noreply.github.com> | 2019-10-17 14:45:23 -0700 |
---|---|---|
committer | Jjp137 <Jjp137@users.noreply.github.com> | 2019-10-22 17:59:12 -0700 |
commit | 93461aee34244a6c004a5572f31a50ff4fad280d (patch) | |
tree | 70e4824a3200d3da50ad567e83453ea1e65aef3c /doc/tut1.rst | |
parent | 6bfa4eb6c51106d9720a61267d47a5e60e3c3d2f (diff) | |
download | Nim-93461aee34244a6c004a5572f31a50ff4fad280d.tar.gz |
Fix many broken links
Note that contrary to what docgen.rst currently says, the ids have to match exactly or else most web browsers will not jump to the intended symbol.
Diffstat (limited to 'doc/tut1.rst')
-rw-r--r-- | doc/tut1.rst | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/doc/tut1.rst b/doc/tut1.rst index fc87fa663..66d156511 100644 --- a/doc/tut1.rst +++ b/doc/tut1.rst @@ -67,8 +67,8 @@ done with spaces only, tabulators are not allowed. String literals are enclosed in double quotes. The ``var`` statement declares a new variable named ``name`` of type ``string`` with the value that is -returned by the `readLine <system.html#readLine,File>`_ procedure. Since the -compiler knows that `readLine <system.html#readLine,File>`_ returns a string, +returned by the `readLine <io.html#readLine,File>`_ procedure. Since the +compiler knows that `readLine <io.html#readLine,File>`_ returns a string, you can leave out the type in the declaration (this is called `local type inference`:idx:). So this will work too: @@ -80,7 +80,7 @@ Note that this is basically the only form of type inference that exists in Nim: it is a good compromise between brevity and readability. The "hello world" program contains several identifiers that are already known -to the compiler: ``echo``, `readLine <system.html#readLine,File>`_, etc. +to the compiler: ``echo``, `readLine <io.html#readLine,File>`_, etc. These built-ins are declared in the system_ module which is implicitly imported by any other module. @@ -326,7 +326,7 @@ the compiler that for every other value nothing should be done: of 3, 8: echo "The number is 3 or 8" else: discard -The empty `discard statement`_ is a *do nothing* statement. The compiler knows +The empty `discard statement <#procedures-discard-statement>`_ is a *do nothing* statement. The compiler knows that a case statement with an else part cannot fail and thus the error disappears. Note that it is impossible to cover all possible string values: that is why string cases always need an ``else`` branch. @@ -359,7 +359,7 @@ For statement ------------- The ``for`` statement is a construct to loop over any element an *iterator* -provides. The example uses the built-in `countup <system.html#countup>`_ +provides. The example uses the built-in `countup <system.html#countup.i,T,T,Positive>`_ iterator: .. code-block:: nim @@ -371,7 +371,7 @@ iterator: The variable ``i`` is implicitly declared by the ``for`` loop and has the type ``int``, because that is what `countup -<system.html#countup>`_ returns. ``i`` runs through the values 1, 2, .., 10. +<system.html#countup.i,T,T,Positive>`_ returns. ``i`` runs through the values 1, 2, .., 10. Each value is ``echo``-ed. This code does the same: .. code-block:: nim @@ -391,7 +391,7 @@ Counting down can be achieved as easily (but is less often needed): # --> Outputs 10 9 8 7 6 5 4 3 2 1 on different lines Since counting up occurs so often in programs, Nim also has a `.. -<system.html#...i,S,T>`_ iterator that does the same: +<system.html#...i,T,T>`_ iterator that does the same: .. code-block:: nim for i in 1..10: @@ -570,8 +570,8 @@ an expression is allowed: Procedures ========== -To define new commands like `echo <system.html#echo>`_ and `readLine -<system.html#readLine,File>`_ in the examples, the concept of a `procedure` +To define new commands like `echo <system.html#echo,varargs[typed,]>`_ and `readLine +<io.html#readLine,File>`_ in the examples, the concept of a `procedure` is needed. (Some languages call them *methods* or *functions*.) In Nim new procedures are defined with the ``proc`` keyword: @@ -753,7 +753,7 @@ Nim provides the ability to overload procedures similar to C++: echo toString(13) # calls the toString(x: int) proc echo toString(true) # calls the toString(x: bool) proc -(Note that ``toString`` is usually the `$ <system.html#$>`_ operator in +(Note that ``toString`` is usually the `$ <dollars.html>`_ operator in Nim.) The compiler chooses the most appropriate proc for the ``toString`` calls. How this overloading resolution algorithm works exactly is not discussed here (it will be specified in the manual soon). However, it does @@ -845,7 +845,7 @@ Let's return to the simple counting example: for i in countup(1, 10): echo i -Can a `countup <system.html#countup>`_ proc be written that supports this +Can a `countup <system.html#countup.i,T,T,Positive>`_ proc be written that supports this loop? Lets try: .. code-block:: nim @@ -1010,7 +1010,7 @@ floats and follow the IEEE-754 standard. Automatic type conversion in expressions with different kinds of floating point types is performed: the smaller type is converted to the larger. Integer types are **not** converted to floating point types automatically, nor vice -versa. Use the `toInt <system.html#toInt>`_ and `toFloat <system.html#toFloat>`_ +versa. Use the `toInt <system.html#toInt,float>`_ and `toFloat <system.html#toFloat,int>`_ procs for these conversions. @@ -1031,13 +1031,13 @@ type as a function: Internal type representation ============================ -As mentioned earlier, the built-in `$ <system.html#$>`_ (stringify) operator +As mentioned earlier, the built-in `$ <dollars.html>`_ (stringify) operator turns any basic type into a string, which you can then print to the console using the ``echo`` proc. However, advanced types, and your own custom types, won't work with the ``$`` operator until you define it for them. Sometimes you just want to debug the current value of a complex type without having to write its ``$`` operator. You can use then the `repr -<system.html#repr>`_ proc which works with any type and even complex data +<system.html#repr,T>`_ proc which works with any type and even complex data graphs with cycles. The following example shows that even for basic types there is a difference between the ``$`` and ``repr`` outputs: @@ -1127,8 +1127,8 @@ Operation Comment ``pred(x, n)`` returns the `n`'th predecessor of `x` ----------------- -------------------------------------------------------- -The `inc <system.html#inc>`_, `dec <system.html#dec>`_, `succ -<system.html#succ>`_ and `pred <system.html#pred>`_ operations can fail by +The `inc <system.html#inc,T,int>`_, `dec <system.html#dec,T,int>`_, `succ +<system.html#succ,T,int>`_ and `pred <system.html#pred,T,int>`_ operations can fail by raising an `EOutOfRange` or `EOverflow` exception. (If the code has been compiled with the proper runtime checks turned on.) @@ -1150,7 +1150,7 @@ compile-time or runtime error. Assignments from the base type to one of its subrange types (and vice versa) are allowed. The ``system`` module defines the important `Natural <system.html#Natural>`_ -type as ``range[0..high(int)]`` (`high <system.html#high>`_ returns the +type as ``range[0..high(int)]`` (`high <system.html#high,typedesc[T]>`_ returns the maximal value). Other programming languages may suggest the use of unsigned integers for natural numbers. This is often **unwise**: you don't want unsigned arithmetic (which wraps around) just because the numbers cannot be negative. @@ -1189,8 +1189,8 @@ Arrays are value types, like any other Nim type. The assignment operator copies the whole array contents. The built-in `len <system.html#len,TOpenArray>`_ proc returns the array's -length. `low(a) <system.html#low>`_ returns the lowest valid index for the -array `a` and `high(a) <system.html#high>`_ the highest valid index. +length. `low(a) <system.html#low,openArray[T]>`_ returns the lowest valid index for the +array `a` and `high(a) <system.html#high,openArray[T]>`_ the highest valid index. .. code-block:: nim :test: "nim c $1" @@ -1265,8 +1265,8 @@ during runtime (like strings). Since sequences are resizable they are always allocated on the heap and garbage collected. Sequences are always indexed with an ``int`` starting at position 0. The `len -<system.html#len,seq[T]>`_, `low <system.html#low>`_ and `high -<system.html#high>`_ operations are available for sequences too. The notation +<system.html#len,seq[T]>`_, `low <system.html#low,openArray[T]>`_ and `high +<system.html#high,openArray[T]>`_ operations are available for sequences too. The notation ``x[i]`` can be used to access the i-th element of ``x``. Sequences can be constructed by the array constructor ``[]`` in conjunction @@ -1318,8 +1318,8 @@ Open arrays Often fixed size arrays turn out to be too inflexible; procedures should be able to deal with arrays of different sizes. The `openarray`:idx: type allows this. Openarrays are always indexed with an ``int`` starting at position 0. -The `len <system.html#len,TOpenArray>`_, `low <system.html#low>`_ and `high -<system.html#high>`_ operations are available for open arrays too. Any array +The `len <system.html#len,TOpenArray>`_, `low <system.html#low,openArray[T]>`_ and `high +<system.html#high,openArray[T]>`_ operations are available for open arrays too. Any array with a compatible base type can be passed to an openarray parameter, the index type does not matter. @@ -1377,8 +1377,8 @@ type conversions in this context: # is transformed by the compiler to: myWriteln(stdout, [$123, $"abc", $4.0]) -In this example `$ <system.html#$>`_ is applied to any argument that is passed -to the parameter ``a``. Note that `$ <system.html#$>`_ applied to strings is a +In this example `$ <dollars.html>`_ is applied to any argument that is passed +to the parameter ``a``. Note that `$ <dollars.html>`_ applied to strings is a nop. @@ -1561,7 +1561,7 @@ having the same field types. Tuples can be *unpacked* during variable assignment (and only then!). This can be handy to assign directly the fields of the tuples to individually named -variables. An example of this is the `splitFile <os.html#splitFile>`_ proc +variables. An example of this is the `splitFile <os.html#splitFile,string>`_ proc from the `os module <os.html>`_ which returns the directory, name and extension of a path at the same time. For tuple unpacking to work you must use parentheses around the values you want to assign the unpacking to, |