Kaynağa Gözat

Update examples with some comments

Matt Coles 9 yıl önce
ebeveyn
işleme
c5427b83c3
2 değiştirilmiş dosya ile 11 ekleme ve 2 silme
  1. 1 1
      examples/examples.mc
  2. 10 1
      examples/fizzbuzz.mc

+ 1 - 1
examples/examples.mc

@@ -32,5 +32,5 @@ characters")
32 32
 (repeat 5 (log 10))
33 33
 (log scopelol)
34 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 36
 (log (str::concat "Hello " "World!"))

+ 10 - 1
examples/fizzbuzz.mc

@@ -1,9 +1,18 @@
1 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 11
 (def fizzbuzz
3 12
   (assign i 1)
4 13
   (repeat $1
5 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 16
     (if (eq (maths::modulo i 5) 0) (assign result (str::concat result "Buzz")))
8 17
     (if (eq result "") (assign result i))
9 18
     (log result)