Rename to Nim
This commit is contained in:
parent
cfdc471535
commit
2bd2af6e1c
25 changed files with 64 additions and 64 deletions
|
|
@ -4,7 +4,7 @@ title: Arrays
|
|||
|
||||
# Arrays
|
||||
|
||||
The arrays in Nimrod are like classic C arrays, their size is specified at compile-time and cannot given or changed at runtime.
|
||||
The arrays in Nim are like classic C arrays, their size is specified at compile-time and cannot given or changed at runtime.
|
||||
|
||||
``` nimrod
|
||||
type
|
||||
|
|
@ -57,7 +57,7 @@ echo mat1 + mat2
|
|||
```
|
||||
|
||||
``` console
|
||||
$ nimrod c -r matrix.nim
|
||||
$ nim c -r matrix.nim
|
||||
1, 1,
|
||||
1, 1,
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ title: Bitsets
|
|||
|
||||
# Bitsets
|
||||
|
||||
Nimrod comes with a built in way to build a set of ordinal types. In order for a type to be usable in a bitset, it must be an ordinal and <<\texttt{high(T)} < 2^{16}>>. For sets of non-ordinal types, see the [sets module](http://nimrod-lang.org/sets.html), which contains hashsets.
|
||||
Nim comes with a built in way to build a set of ordinal types. In order for a type to be usable in a bitset, it must be an ordinal and <<\texttt{high(T)} < 2^{16}>>. For sets of non-ordinal types, see the [sets module](http://nim-lang.org/sets.html), which contains hashsets.
|
||||
|
||||
However, best practice is to keep bitset size significantly smaller since each possible element in the set consumes one bit, therefore a bitset of <<2^{16}>> elements will consume 64KiB.
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ block:
|
|||
let b = "3" # shadowing is probably a dumb idea
|
||||
```
|
||||
|
||||
Parentheses can be used as an expression, but they do not provide end of statement inference, so it is necessary to place semicolons yourself. An interesting and unexpected side effect of this syntax is that Nimrod is suitable even for brace purists!
|
||||
Parentheses can be used as an expression, but they do not provide end of statement inference, so it is necessary to place semicolons yourself. An interesting and unexpected side effect of this syntax is that Nim is suitable even for brace purists!
|
||||
|
||||
``` nimrod
|
||||
proc square(inSeq: seq[float]): seq[float] = (
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ title: Case Statements
|
|||
---
|
||||
# Case Statements
|
||||
|
||||
Nimrod also supports case statements, which are like switches in other languages. There are several things to note here:
|
||||
Nim also supports case statements, which are like switches in other languages. There are several things to note here:
|
||||
|
||||
* You can use strings in the switch statement
|
||||
* Sets and ranges of ordinal types are also usable
|
||||
|
|
@ -44,7 +44,7 @@ echo positiveOrNegative(-1)
|
|||
```
|
||||
|
||||
``` console
|
||||
$ nimrod c -r ./case_stmts.nim
|
||||
$ nim c -r ./case_stmts.nim
|
||||
C
|
||||
Consonant
|
||||
negative
|
||||
|
|
@ -61,6 +61,6 @@ case (x and 3) + 7:
|
|||
of 10: echo "D"
|
||||
```
|
||||
``` console
|
||||
$ nimrod c -r ./case_stmts_1.nim
|
||||
$ nim c -r ./case_stmts_1.nim
|
||||
C
|
||||
```
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ title: For Loops & Iterators
|
|||
---
|
||||
# For Loops & Iterators
|
||||
|
||||
Nimrod has first class iterators and syntax to use them, for loops. The `continue` and `break` keywords also work inside of for loops. There are two kinds of iterator, and two special methods that for loops work with.
|
||||
Nim has first class iterators and syntax to use them, for loops. The `continue` and `break` keywords also work inside of for loops. There are two kinds of iterator, and two special methods that for loops work with.
|
||||
|
||||
## `items` and `pair`
|
||||
|
||||
When iterating over an object with one item, Nimrod will call an iterator called `items` with the first parameter the type you want to iterate over. The same thing happens when iterating with two items, but in that case, the `pairs` iterator is called.
|
||||
When iterating over an object with one item, Nim will call an iterator called `items` with the first parameter the type you want to iterate over. The same thing happens when iterating with two items, but in that case, the `pairs` iterator is called.
|
||||
|
||||
``` nimrod
|
||||
type
|
||||
|
|
@ -29,7 +29,7 @@ for i, c in TRange(low: 1, high: 3):
|
|||
echo c
|
||||
```
|
||||
``` console
|
||||
$ nimrod c -r items_pair.nim
|
||||
$ nim c -r items_pair.nim
|
||||
b
|
||||
c
|
||||
d
|
||||
|
|
@ -50,7 +50,7 @@ for i in 0...5:
|
|||
echo i
|
||||
```
|
||||
``` console
|
||||
$ nimrod c -r operatoriterator.nim
|
||||
$ nim c -r operatoriterator.nim
|
||||
0
|
||||
1
|
||||
2
|
||||
|
|
@ -73,7 +73,7 @@ for i in countTo(5):
|
|||
echo i
|
||||
```
|
||||
```console
|
||||
$ nimrod c -r ./inline_iter.nim
|
||||
$ nim c -r ./inline_iter.nim
|
||||
0
|
||||
1
|
||||
2
|
||||
|
|
@ -118,7 +118,7 @@ for i in countTo9():
|
|||
echo output
|
||||
```
|
||||
```console
|
||||
$ nimrod c -r ./closure_iter.nim
|
||||
$ nim c -r ./closure_iter.nim
|
||||
0
|
||||
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
||||
0123456789
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
title: Getting Started
|
||||
---
|
||||
# Getting Started
|
||||
When installing Nimrod, you have two options: downloading a copy directly from git, or downloading a prepackaged distribution from the website
|
||||
When installing Nim, you have two options: downloading a copy directly from git, or downloading a prepackaged distribution from the website
|
||||
|
||||
## Downloading a Nimrod Distribution
|
||||
To get started with Nimrod, head over to the [downloads page](http://nimrod-lang.org/download.html) and download the version you'd like.
|
||||
## Downloading a Nim Distribution
|
||||
To get started with Nim, head over to the [downloads page](http://nim-lang.org/download.html) and download the version you'd like.
|
||||
|
||||
The Windows distribution comes with the MinGW compiler, which is recommended, but if you'd like to use your own compiler, download the version without MinGW.
|
||||
|
||||
|
|
@ -13,23 +13,23 @@ On Mac and Linux, it is recommended to use either GCC or Clang.
|
|||
|
||||
| | i386 | amd64 |
|
||||
| -- | ---- | ----- |
|
||||
| Windows | [Download](http://nimrod-lang.org/download/nimrod_0.9.4_windows_i386_full.zip) ([w/o MinGW](http://nimrod-lang.org/download/nimrod_0.9.4_windows_i386_slim.zip))| [Download](http://nimrod-lang.org/download/nimrod_0.9.4_windows_amd64_full.zip) ([w/o MinGW](http://nimrod-lang.org/download/nimrod_0.9.4_windows_amd64_slim.zip)) |
|
||||
| Mac | NA | [Download](http://nimrod-lang.org/download/nimrod_0.9.4_macosx_amd64.zip) |
|
||||
| Linux | [Download](http://nimrod-lang.org/download/nimrod_0.9.4_linux_i386.tar.gz) | [Download](http://nimrod-lang.org/download/nimrod_0.9.4_linux_amd64.tar.gz) |
|
||||
| Windows | [Download](http://nim-lang.org/download/nim_0.9.4_windows_i386_full.zip) ([w/o MinGW](http://nim-lang.org/download/nim_0.9.4_windows_i386_slim.zip))| [Download](http://nim-lang.org/download/nim_0.9.4_windows_amd64_full.zip) ([w/o MinGW](http://nim-lang.org/download/nim_0.9.4_windows_amd64_slim.zip)) |
|
||||
| Mac | NA | [Download](http://nim-lang.org/download/nim_0.9.4_macosx_amd64.zip) |
|
||||
| Linux | [Download](http://nim-lang.org/download/nim_0.9.4_linux_i386.tar.gz) | [Download](http://nim-lang.org/download/nim_0.9.4_linux_amd64.tar.gz) |
|
||||
|
||||
Once you have downloaded the appropriate distribution and extracted the files somewhere convenient, feel free to place the `bin` directory in the path for easier access.
|
||||
|
||||
## Downloading from Git
|
||||
To install Nimrod from git, ensure that you have gcc installed on Windows, Linux, and BSDs and clang on Mac. Afterwards, run the following series of commands to download and bootstrap Nimrod:
|
||||
To install Nim from git, ensure that you have gcc installed on Windows, Linux, and BSDs and clang on Mac. Afterwards, run the following series of commands to download and bootstrap Nim:
|
||||
|
||||
```console
|
||||
$ git clone -b master git://github.com/Araq/Nimrod.git
|
||||
$ cd Nimrod
|
||||
$ git clone --depth 1 git://github.com/nimrod-code/csources
|
||||
$ git clone -b master git://github.com/Araq/Nim.git
|
||||
$ cd Nim
|
||||
$ git clone --depth 1 git://github.com/nim-code/csources
|
||||
$ cd csources
|
||||
$ sh build.sh # Replace with build.bat on windows
|
||||
$ cd ..
|
||||
$ bin/nimrod c koch
|
||||
$ bin/nim c koch
|
||||
$ ./koch boot -d:release
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ echo "Hello World"
|
|||
Save this text as `helloworld.nim`. To compile and execute the program, the following command should be run
|
||||
|
||||
``` console
|
||||
$ nimrod c -r --verbosity:0 helloworld.nim
|
||||
$ nim c -r --verbosity:0 helloworld.nim
|
||||
Hello World
|
||||
```
|
||||
|
||||
The command has several elements:
|
||||
|
||||
* `c` is an alias for `compile`, which compiles the Nimrod sources into C and then invokes the C compiler on them
|
||||
* `c` is an alias for `compile`, which compiles the Nim sources into C and then invokes the C compiler on them
|
||||
* `-r` is an alias for `--run`, which runs the program
|
||||
* `--verbosity:0` makes the compiler only output essential messages, since by default it also outputs some debugging messages. From now on, we assume that `--verbosity:0` is set
|
||||
* `./helloworld.nim` is the path to the source you want to compile
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ title: If, Else, While
|
|||
|
||||
# If, Else, While
|
||||
|
||||
Nimrod has many different control flow constructs, including the standard `if`s, `else`s, and `while`s. However, Nimrod does not use an `else if` construct like many languages, it uses a more condensed `elif`.
|
||||
Nim has many different control flow constructs, including the standard `if`s, `else`s, and `while`s. However, Nim does not use an `else if` construct like many languages, it uses a more condensed `elif`.
|
||||
|
||||
When inside a loop, `continue` can be used to skip the rest of the loop body and to begin the next iteration; `break` can be used to immediately leave the loop body.
|
||||
|
||||
Along with [its other uses](/block/), the `block` statement can be used to create a label so that it's possible to break out of nested loops.
|
||||
|
||||
<!--skip-->``` nimrod
|
||||
<!--skip-->``` nim
|
||||
import strutils, math
|
||||
|
||||
randomize()
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
title: Main
|
||||
---
|
||||
|
||||
# Nimrod by Example
|
||||
# Nim by Example
|
||||
|
||||
[Nimrod] is a powerful statically typed language that allows the programmer expressiveness without compromising run-time performance. As a general purpose programming language, it gives the same sort of power and performance as C++, but in a nicer package and with even more powerful tools!
|
||||
[Nim] is a powerful statically typed language that allows the programmer expressiveness without compromising run-time performance. As a general purpose programming language, it gives the same sort of power and performance as C++, but in a nicer package and with even more powerful tools!
|
||||
|
||||
[Nimrod]: http://nimrod-lang.org/
|
||||
[Nim]: http://nim-lang.org/
|
||||
|
||||
Getting started? Head over to the [installation instructions](/getting_started/)!
|
||||
|
||||
<!--skip-->``` nimrod
|
||||
<!--skip-->``` nim
|
||||
import tables, strutils
|
||||
|
||||
var wordFrequencies = initCountTable[string]()
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ for a in animals:
|
|||
echo a.ageHumanYrs()
|
||||
```
|
||||
``` console
|
||||
$ nimrod c -r oop.nim
|
||||
$ nim c -r oop.nim
|
||||
woof
|
||||
70
|
||||
meow
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ title: OOP Macro
|
|||
<!--- Thanks to fowl for creating this page, filwit for fixing some oddities -->
|
||||
|
||||
# OOP Macro
|
||||
This is the code that we currently must write to use OOP in Nimrod:
|
||||
This is the code that we currently must write to use OOP in Nim:
|
||||
|
||||
```nimrod
|
||||
type Animal = ref object of TObject
|
||||
|
|
@ -47,7 +47,7 @@ macro class*(head: expr, body: stmt): stmt {.immediate.} =
|
|||
# The macro is immediate so that it doesn't
|
||||
# resolve identifiers passed to it
|
||||
|
||||
var typeName, baseName: PNimrodNode
|
||||
var typeName, baseName: PNimNode
|
||||
|
||||
if head.kind == NnkIdent:
|
||||
# `head` is expression `typeName`
|
||||
|
|
@ -222,7 +222,7 @@ for a in animals:
|
|||
echo a.age_human_yrs()
|
||||
```
|
||||
``` console
|
||||
$ nimrod c -r oopmacro.nim
|
||||
$ nim c -r oopmacro.nim
|
||||
woof
|
||||
70
|
||||
meow
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ The following code depends on the ``opengl`` and ``nim-glfw`` packages which
|
|||
can be installed via babel by executing ``babel install opengl@#head nim-glfw@#head``.
|
||||
You will need the GLFW DLL in order to run this on Windows.
|
||||
|
||||

|
||||

|
||||
|
||||
One thing to keep in mind when writing OpenGL code in Nimrod is that ``float``
|
||||
One thing to keep in mind when writing OpenGL code in Nim is that ``float``
|
||||
is actually ``float64``. But vertices must be ``float32`` so you must explicitly
|
||||
specify that by casting or using ``'f32`` as is done in the example.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ title: Primitives
|
|||
---
|
||||
# Primitives
|
||||
|
||||
Nimrod has several primitive types:
|
||||
Nim has several primitive types:
|
||||
|
||||
* signed integers: `int8`, `int16`, `int32`, `int64`, and `int`, where `int` is the same size as a pointer
|
||||
* unsigned integers are similar with `u` prepended to the type
|
||||
|
|
@ -31,7 +31,7 @@ let
|
|||
echo 4/2
|
||||
```
|
||||
``` console
|
||||
$ nimrod c -r numbers2.nim
|
||||
$ nim c -r numbers2.nim
|
||||
2.0
|
||||
```
|
||||
Another difference that may be surprising is that the `/` operator returns a floating point result, even when the operands are integers. If integer division is needed, the `div` operator should be used.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ title: Procs
|
|||
---
|
||||
# Procs
|
||||
|
||||
Procedures in Nimrod are declared using `proc` and require that their parameter and return types be annotated. After the types and parameters, an `=` is used to denote the start of the function body. Another thing to note is that procedures have uniform function call syntax, which means that they can called as both `foo(a, b)` or `a.foo(b)`.
|
||||
Procedures in Nim are declared using `proc` and require that their parameter and return types be annotated. After the types and parameters, an `=` is used to denote the start of the function body. Another thing to note is that procedures have uniform function call syntax, which means that they can called as both `foo(a, b)` or `a.foo(b)`.
|
||||
|
||||
``` nimrod
|
||||
proc fibonacci(n: int): int =
|
||||
|
|
@ -30,7 +30,7 @@ echo bar() # will not compile
|
|||
|
||||
## Side effect analyses
|
||||
|
||||
Nimrod provides support for functional programming and so includes the `{.noSideEffect.}` pragma, which statically ensures there are no side effects.
|
||||
Nim provides support for functional programming and so includes the `{.noSideEffect.}` pragma, which statically ensures there are no side effects.
|
||||
|
||||
``` nimrod
|
||||
proc sum(x, y: int): int {. noSideEffect .} =
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ title: First Class Functions
|
|||
|
||||
# First Class Functions
|
||||
|
||||
Nimrod supports closures as well as passing functions. Two different syntaxes available for closures, proc syntax, which is identical to regular procedure syntax, and "do notation", which is a bit shorter.
|
||||
Nim supports closures as well as passing functions. Two different syntaxes available for closures, proc syntax, which is identical to regular procedure syntax, and "do notation", which is a bit shorter.
|
||||
|
||||
``` nimrod
|
||||
import sequtils
|
||||
|
|
@ -15,7 +15,7 @@ echo powersOfTwo.filter do (x: int) -> bool : x > 32
|
|||
echo powersOfTwo.filter(proc (x: int): bool = x > 32)
|
||||
```
|
||||
``` console
|
||||
$ nimrod c -r filterclosure.nim
|
||||
$ nim c -r filterclosure.nim
|
||||
@[64, 128, 256]
|
||||
@[64, 128, 256]
|
||||
```
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ echo r" "" "
|
|||
echo re"\b[a-z]++\b"
|
||||
```
|
||||
``` console
|
||||
$ nimrod c -r strings.nim
|
||||
$ nim c -r strings.nim
|
||||
words words words ⚑
|
||||
<html>
|
||||
<head>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
title: Enums
|
||||
---
|
||||
# Enums
|
||||
Enums in Nimrod are like enums in C, but are type-checked. There are no anonymous enums in Nimrod.
|
||||
Enums in Nim are like enums in C, but are type-checked. There are no anonymous enums in Nim.
|
||||
|
||||
``` nimrod
|
||||
type
|
||||
|
|
@ -34,7 +34,7 @@ dec ordinal
|
|||
echo high(char)
|
||||
```
|
||||
```console
|
||||
$ nimrod c -r enums.nim
|
||||
$ nim c -r enums.nim
|
||||
cdNorth ord: 0
|
||||
cdEast ord: 1
|
||||
cdSouth ord: 2
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ title: Objects
|
|||
---
|
||||
# Objects
|
||||
|
||||
In Nimrod, objects are like structs from C family languages and define a grouping of fields. They are by default traced by the garbage collector, so there is no need to explicitly free them when allocated.
|
||||
In Nim, objects are like structs from C family languages and define a grouping of fields. They are by default traced by the garbage collector, so there is no need to explicitly free them when allocated.
|
||||
|
||||
``` nimrod
|
||||
type
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ proc printThings(things: varargs[string]) =
|
|||
printThings "words", "to", "print"
|
||||
```
|
||||
```console
|
||||
$ nimrod c -r ./varargs1.nim
|
||||
$ nim c -r ./varargs1.nim
|
||||
words
|
||||
to
|
||||
print
|
||||
|
|
@ -36,7 +36,7 @@ printThings "thing 1", 2, @[4, 5, 6]
|
|||
```
|
||||
|
||||
```console
|
||||
$ nimrod c -r ./varargs2.nim
|
||||
$ nim c -r ./varargs2.nim
|
||||
thing 1
|
||||
2
|
||||
@[4, 5, 6]
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ title: Variables
|
|||
---
|
||||
# Variables
|
||||
|
||||
Nimrod supports three different types of variables, `let`, `var`, and `const`. As with most things, multiple variables can be declared in the same section.
|
||||
Nim supports three different types of variables, `let`, `var`, and `const`. As with most things, multiple variables can be declared in the same section.
|
||||
|
||||
``` nimrod
|
||||
proc getAlphabet(): string =
|
||||
|
|
@ -43,7 +43,7 @@ e += 1
|
|||
```
|
||||
|
||||
``` console
|
||||
$ nimrod c --verbosity:2 ./variables.nim
|
||||
$ nim c --verbosity:2 ./variables.nim
|
||||
variables.nim(22, 2) Error: 'let' symbol requires an initialization
|
||||
f: float
|
||||
^
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ title: Type Casting and Inference
|
|||
---
|
||||
# Type Casting and Inference
|
||||
|
||||
Nimrod is a statically typed language. As such, each variable has a type associated with it. As seen in the previous example these types are inferred in the `const`, `let` and `var` declarations by the compiler.
|
||||
Nim is a statically typed language. As such, each variable has a type associated with it. As seen in the previous example these types are inferred in the `const`, `let` and `var` declarations by the compiler.
|
||||
|
||||
```nimrod
|
||||
# These types are inferred.
|
||||
|
|
@ -15,7 +15,7 @@ x = y
|
|||
```
|
||||
|
||||
```console
|
||||
$ nimrod c -r typeinference.nim
|
||||
$ nim c -r typeinference.nim
|
||||
typeinference.nim(6, 4) Error: type mismatch: got (string) but expected 'int'
|
||||
```
|
||||
|
||||
|
|
@ -33,6 +33,6 @@ ffi(cast[ptr array[6, char]](addr y[0]))
|
|||
```
|
||||
|
||||
```console
|
||||
$ nimrod c -r typecasting.nim
|
||||
$ nim c -r typecasting.nim
|
||||
ref 002C8030 --> ['F', 'o', 'o', 'b', 'a', 'r']
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue