4 ms·
There are no code examples on the home page, so here's one: (defn bottles [n] (match n 0 "No more bottles" 1 "1 bottle" _
by shaicoleman 4y ago
There are no code examples on the home page, so here's one:
(defn bottles [n]
(match n
0 "No more bottles"
1 "1 bottle"
_ (string n " bottles")))
(loop [i :down [99 0]]
(print
(bottles i) " of beer on the wall\n"
(bottles i) " of beer\nTake one down, pass it around\n"
(bottles (- i 1)) " of beer on the wall\n\n"))
https://rosettacode.org/wiki/99_bottles_of_beer#Janet https://rosettacode.org/wiki/99_bottles_of_beer#Janet
- cmiles74 4y agoI had some time a while back to work on a project of my own, I coded up a bencode parser in Janet. It was a fun project, I liked Janet alot. :-) https://github.com/cmiles74/bencode/blob/master/src/bencode.janet https://github.com/cmiles74/bencode/blob/master/src/bencode....
- mdgrech23 4y agobottles 99 of beer on the wall? That's not the lyrics or am I just not understanding janet?
- bombastry 4y agoThe prefix notation may be throwing you off or perhaps you have mistaken the function `bottles` for the string "bottles". The code `(bottles i)` in the loop is calling the function `bottles` (defined at the top) with the argument `i`. The value of `(bottles 99)` is `(string 99 " bottles")` which evaluates to "99 bottles", as expected.
- colonCapitalDee 4y agoYou aren't understanding Janet. (bottles i) invokes the bottles function with parameter i, so the lyric is "99 bottles of beer on the wall".
- deleted 4y ago[deleted]