about summary refs log tree commit diff stats
path: root/054string-equal.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-05-16 18:37:45 -0700
committerKartik Agaram <vc@akkartik.com>2020-05-18 00:44:50 -0700
commitc21bf3973921e64b66ad33733a003b0f17b795cb (patch)
treeb136b22abef8c62344a6a65a3abc56440ae0d732 /054string-equal.subx
parent50982c5cdc6c633c9be824f2213dd7e2321f0641 (diff)
downloadmu-c21bf3973921e64b66ad33733a003b0f17b795cb.tar.gz
-
Diffstat (limited to '054string-equal.subx')
0 files changed, 0 insertions, 0 deletions
amp;id=b0bf5321de2ba32f3b92c2faf6b7b68a06b6b432'>b0bf5321 ^
77d5b5d6 ^
1ae2ff1c ^
b0bf5321 ^
b7830945 ^
b96af395 ^
d1c12218 ^
1ead3562 ^
77d5b5d6 ^
b96af395 ^
b0bf5321 ^
b96af395 ^
b0bf5321 ^
b96af395 ^
ce87c19e ^


b96af395 ^
1ead3562 ^
d2244a2f ^
1ead3562 ^
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

                                                                          
 
                                                                  

                                        
 
 
                                                                                                    
             
                  
                                                                                                                  
                               
 
 
          
             
             
                                            
             
                                            
                                             


                                          
                 
                                           
                                                                   
                                                     
 
# example program: maintain multiple counters with isolated lexical scopes
# (spaces)

def new-counter n:number -> default-space:address:array:location [
  default-space <- new location:type, 30
  load-ingredients
]

def increment-counter outer:address:array:location/names:new-counter, x:number -> n:number/space:1 [
  local-scope
  load-ingredients
  0:address:array:location/names:new-counter <- copy outer  # setup outer space; it *must* come from 'new-counter'
  n/space:1 <- add n/space:1, x
]

def main [
  local-scope
  # counter A
  a:address:array:location <- new-counter 34
  # counter B
  b:address:array:location <- new-counter 23
  # increment both by 2 but in different ways
  increment-counter a, 1
  b-value:number <- increment-counter b, 2
  a-value:number <- increment-counter a, 1
  # check results
  $print [Contents of counters], 10/newline
  # trailing space in next line is to help with syntax highlighting
  $print [a: ], a-value, [ b: ], b-value,  10/newline
]