summary refs log tree commit diff stats
path: root/doc/tools.rst
blob: f407420b08158fe556674b89b87535a944e30c6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
========================
Tools available with Nim
========================

The standard distribution ships with the following tools:

- | `Hot code reloading <hcr.html>`_
  | The "Hot code reloading" feature is built into the compiler but has its own
    document explaining how it works.

- | `Documentation generator <docgen.html>`_
  | The builtin document generator ``nim doc`` generates HTML documentation
    from ``.nim`` source files.

- | `Nimsuggest for IDE support <nimsuggest.html>`_
  | Through the ``nimsuggest`` tool, any IDE can query a ``.nim`` source file
    and obtain useful information like definition of symbols or suggestions for
    completion.

- | `C2nim <https://github.com/nim-lang/c2nim/blob/master/doc/c2nim.rst>`_
  | C to Nim source converter. Translates C header files to Nim.

- | `niminst <https://nim-lang.org/docs/niminst.html>`_
  | niminst is a tool to generate an installer for a Nim program.

- | `nimgrep <nimgrep.html>`_
  | Nim search and replace utility.

- | nimpretty
  | ``nimpretty`` is a Nim source code beautifier,
    to format code according to the official style guide.
Kartik K. Agaram <vc@akkartik.com> 2014-11-17 01:19:21 -0800 268 - recursive function: factorial' href='/akkartik/mu/commit/factorial.mu?h=hlt&id=08b48a8d56e6e683a1d3bfa118334b48937b12bd'>08b48a8d ^
b96af395 ^


bc643692 ^
b96af395 ^
bafc7192 ^
b96af395 ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

                                             
          
             
                         
                          


 
                                         
             
                  

                     

                               
            
   
                             

                                 
                                 
 
 


                         
                           
   
                         


            
# example program: compute the factorial of 5

def main [
  local-scope
  x:number <- factorial 5
  $print [result: ], x, [ 
]
]

def factorial n:number -> result:number [
  local-scope
  load-ingredients
  {
    # if n=0 return 1
    zero?:boolean <- equal n, 0
    break-unless zero?
    return 1
  }
  # return n * factorial(n-1)
  x:number <- subtract n, 1
  subresult:number <- factorial x
  result <- multiply subresult, n
]

# unit test
scenario factorial-test [
  run [
    1:number <- factorial 5
  ]
  memory-should-contain [
    1 <- 120
  ]
]