Sfoglia il codice sorgente

Update examples with some comments

Matt Coles 9 anni fa
parent
commit
c5427b83c3
2 ha cambiato i file con 11 aggiunte e 2 eliminazioni
  1. 1 1
      examples/examples.mc
  2. 10 1
      examples/fizzbuzz.mc

+ 1 - 1
examples/examples.mc

32
 (repeat 5 (log 10))
32
 (repeat 5 (log 10))
33
 (log scopelol)
33
 (log scopelol)
34
 (repeat scopelol (log 10))
34
 (repeat scopelol (log 10))
35
-(if (eq 2 scopelol) (log "2 == scopelol") | (log "2 != scopelol"))
35
+(if (eq 2 scopelol) (log "2 == scopelol") | (log "2 != scopelol")) ; Using a bar is similar to 'else' in a normal language
36
 (log (str::concat "Hello " "World!"))
36
 (log (str::concat "Hello " "World!"))

+ 10 - 1
examples/fizzbuzz.mc

1
 (include str maths)
1
 (include str maths)
2
+
3
+;
4
+; def: fizzbuzz(1)
5
+;
6
+; Takes an argument and prints the numbers up to and including the argument
7
+; replacing numbers that are divisible by 3, with Fizz, numbers
8
+; divisible by 5 with Buzz, and numbers that are divisible by both,
9
+; with FizzBuzz
10
+;
2
 (def fizzbuzz
11
 (def fizzbuzz
3
   (assign i 1)
12
   (assign i 1)
4
   (repeat $1
13
   (repeat $1
5
     (assign result "")
14
     (assign result "")
6
-    (if (eq (maths::modulo i 3) 0) (assign result (str::concat result "Fizz")))
15
+    (if (eq (maths::modulo i 3) 0) (assign result "Fizz"))
7
     (if (eq (maths::modulo i 5) 0) (assign result (str::concat result "Buzz")))
16
     (if (eq (maths::modulo i 5) 0) (assign result (str::concat result "Buzz")))
8
     (if (eq result "") (assign result i))
17
     (if (eq result "") (assign result i))
9
     (log result)
18
     (log result)