summary refs log tree commit diff stats
path: root/lib/system/iterators_1.nim
Commit message (Collapse)AuthorAgeFilesLines
* Change stdlib imports to use std prefix in most examples (#17202)Danil Yarantsev2021-02-281-3/+3
|
* clean up old codes (#16284)flywind2020-12-091-144/+101
| | | | | | | * clean up old codes * fix docs and links * clean
* fixes #14001 (#14004)Andreas Rumpf2020-04-191-5/+5
|
* System cleanup, part 2 (#13155)Miran2020-01-151-0/+214
* create basic_types, arithmetics, exceptions, comparisons * create setops.nim * create memalloc.nim * create gc_interface.nim * create iterators_1.nim
05:23:22 -0800 344 - about to give up on rewrite rules' href='/akkartik/mu/commit/generic.mu?h=main&id=6952b8f0693920b7ad27793a75defaca5ef31a9d'>6952b8f0 ^
d4b4d018 ^



f184c95e ^

0ca35d02 ^
6952b8f0 ^
f184c95e ^
d4b4d018 ^


f184c95e ^


0ca35d02 ^
d4b4d018 ^



f184c95e ^
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
                                                                             
                                                            
 

                                
                                                               
                                
              



                                                          

  
                 
                               
         


                                                


   
                



                                          
  
; To demonstrate generic functions, we'll construct a factorial function with
; separate base and recursive clauses. Compare factorial.mu.

; factorial n = n*factorial(n-1)
(function factorial [
  (default-space:space-address <- new space:literal 30:literal)
  (n:integer <- input 0:literal)
  more-clauses
  (x:integer <- subtract n:integer 1:literal)
  (subresult:integer <- factorial x:integer)
  (result:integer <- multiply subresult:integer n:integer)
  (reply result:integer)
])

; factorial 0 = 1
(after factorial/more-clauses [
  { begin
    (zero?:boolean <- equal n:integer 0:literal)
    (break-unless zero?:boolean)
    (reply 1:literal)
  }
])

(function main [
  (1:integer <- factorial 5:literal)
  (print-primitive (("result: " literal)))
  (print-primitive 1:integer)
  (print-primitive (("\n" literal)))
])