about summary refs log tree commit diff stats
path: root/subx/001help.cc
Commit message (Expand)AuthorAgeFilesLines
* 4857Kartik Agaram2018-12-061-3/+12
* 4694Kartik Agaram2018-10-131-0/+5
* 4637 - subx: support multiple input filesKartik Agaram2018-10-011-1/+1
* 4624Kartik Agaram2018-09-301-1/+1
* 4436Kartik Agaram2018-07-271-2/+8
* 4427 - support for '--trace' argvKartik Agaram2018-07-261-0/+15
* 4413Kartik Agaram2018-07-251-3/+1
* 4412Kartik Agaram2018-07-251-1/+1
* 4411Kartik Agaram2018-07-251-2/+6
* 4409Kartik Agaram2018-07-251-3/+7
* 4381Kartik Agaram2018-07-201-0/+3
* 4378Kartik Agaram2018-07-201-1/+1
* 4376 - subx: online help includes supported opcodesKartik Agaram2018-07-201-3/+5
* 4375Kartik Agaram2018-07-201-20/+19
* 4374 - starting to use the online help systemKartik Agaram2018-07-201-1/+3
* 4373 - subx: beginnings of online helpKartik Agaram2018-07-201-9/+46
* 4289 - beginnings of a translator to ELFKartik Agaram2018-06-301-3/+2
* 4277 - make room for a 'compile' sub-commandKartik Agaram2018-06-271-1/+3
* 4276 - switching gears to subxKartik Agaram2018-06-271-1/+4
* 4063Kartik K. Agaram2017-10-141-2/+2
* 4014 - core skeleton for x86 interpreterKartik K. Agaram2017-10-111-16/+4
* 4011 - start of sub-x86 VMKartik K. Agaram2017-10-091-2/+2
* 3930 - experimental bytecode interpreterKartik K. Agaram2017-06-191-0/+220
rtik.com> 2016-09-17 00:43:13 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2016-09-17 00:43:20 -0700 3380' href='/akkartik/mu/commit/factorial.mu?h=main&id=192d59d3bb9ee0baa1afd82cb5d0f352bdc6e403'>192d59d3 ^
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:num <- factorial 5
  $print [result: ], x, [ 
]
]

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

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