-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
340 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
# Lyrics from the song: | ||
# | ||
# | ||
# 99 bottles of beer on the wall | ||
# 99 bottles of beer | ||
# Take one down, pass it around | ||
# 98 bottles of beer on the wall | ||
# | ||
# | ||
# 98 bottles of beer on the wall | ||
# 98 bottles of beer | ||
# Take one down, pass it around | ||
# 97 bottles of beer on the wall | ||
|
||
|
||
(let arg (if (>= (len sys:args) 1) (toNumber (@ sys:args 0)) nil)) | ||
(let i (if (nil? arg) 100 arg)) | ||
(let arg | ||
(if (>= (len sys:args) 1) | ||
(toNumber (@ sys:args 0)) | ||
nil)) | ||
(let i | ||
(if (nil? arg) | ||
100 | ||
arg)) | ||
|
||
(mut n i) | ||
(while (> n 1) { | ||
(print (str:format "{} Bottles of beer on the wall\n{} bottles of beer\nTake one down, pass it around" n n)) | ||
(set n (- n 1)) | ||
(print (str:format "{} Bottles of beer on the wall." n))}) | ||
(print (str:format "{} Bottles of beer on the wall\n{} bottles of beer\nTake one down, pass it around" n n)) | ||
(set n (- n 1)) | ||
(print (str:format "{} Bottles of beer on the wall." n)) }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
# a function which just prints its argument | ||
(let egg (fun (bar) (print bar))) | ||
|
||
# the data we're going to give to this function | ||
(let data ["Iron Man" "is" "Tony Stark"]) | ||
|
||
# a list of function call which should be executed later on | ||
(mut callbacks []) | ||
|
||
(print "Data: " data) | ||
(print "Generating callbacks") | ||
(mut acc 0) | ||
|
||
# here we are filling the list callbacks | ||
(while (!= acc (len data)) { | ||
(mut d (@ data acc)) | ||
# by putting in it closures that captured d, an element of `data` | ||
# and call the function egg on it | ||
(set callbacks (append callbacks (fun (&d) (egg d)))) | ||
(set acc (+ 1 acc))}) | ||
(mut d (@ data acc)) | ||
|
||
# by putting in it closures that captured d, an element of `data` | ||
# and call the function egg on it | ||
(set callbacks (append callbacks (fun (&d) (egg d)))) | ||
(set acc (+ 1 acc)) }) | ||
|
||
# then we reset the accumulator | ||
(set acc 0) | ||
(while (!= acc (len callbacks)) { | ||
# we print what was stored in the closure using dot notation | ||
(mut stored (@ callbacks acc)) | ||
(print "stored: " stored.d) | ||
# and then we call the closure itself (be careful: (@ callbacks acc) only returns the callback, | ||
# thus we need to put it in another pair of parens to call the callback) | ||
(puts "Calling callback number " acc ": ") | ||
((@ callbacks acc)) | ||
(set acc (+ 1 acc))}) | ||
# we print what was stored in the closure using dot notation | ||
(mut stored (@ callbacks acc)) | ||
(print "stored: " stored.d) | ||
|
||
# and then we call the closure itself (be careful: (@ callbacks acc) only returns the callback, | ||
# thus we need to put it in another pair of parens to call the callback) | ||
(puts "Calling callback number " acc ": ") | ||
((@ callbacks acc)) | ||
(set acc (+ 1 acc)) }) |
Oops, something went wrong.