github.com/nevalang/neva@v0.23.1-0.20240507185603-7696a9bb8dda/e2e/99_bottles_with_chain/main/main.neva (about) 1 // https://www.99-bottles-of-beer.net 2 3 component Main(start) (stop) { 4 nodes { Match<int>, next PrintNext2Lines } 5 6 :start -> (99 -> next:n -> match:data) 7 -1 -> match:case[0] -> :stop 8 match:else -> next:n 9 } 10 11 component PrintNext2Lines(n int) (n int) { 12 nodes { 13 decr Decr<int> 14 first PrintFirstLine 15 second PrintSecondLine 16 } 17 :n -> first:n -> decr:n -> second:n -> :n 18 } 19 20 // === First Line === 21 22 const { 23 firstLine1 string = '$0 bottles of beer on the wall, $0 bottles of beer.\n' 24 firstLine2 string = '1 bottle of beer on the wall, 1 bottle of beer.' 25 firstLine3 string = 'No more bottles of beer on the wall, no more bottles of beer.' 26 } 27 28 component PrintFirstLine(n int) (n int) { 29 nodes { Match<int>, Println, Printf, Lock<int> } 30 31 :n -> [match:data, lock:data] 32 33 0 -> match:case[0] -> ($firstLine3 -> println:data) 34 1 -> match:case[1] -> ($firstLine2 -> println:data) 35 match:else -> [ 36 printf:args[0], 37 ($firstLine1 -> printf:tpl) 38 ] 39 40 [println:sig, printf:args[0]] -> lock:sig 41 lock:data -> :n 42 } 43 44 // === Second Line === 45 46 const { 47 secondLine1 string = 'Take one down and pass it around, $0 bottles of beer on the wall.\n\n' 48 secondLine2 string = 'Take one down and pass it around, 1 bottle of beer on the wall.\n' 49 secondLine3 string = 'Take one down and pass it around, no more bottles of beer on the wall.\n' 50 secondLine4 string = 'Go to the store and buy some more, 99 bottles of beer on the wall.' 51 } 52 53 component PrintSecondLine(n int) (n int) { 54 nodes { Match<int>, Lock<int>, Printf, Println } 55 56 :n -> [match:data, lock:data] 57 58 -1 -> match:case[0] -> ($secondLine4 -> println:data) 59 0 -> match:case[1] -> ($secondLine3 -> println:data) 60 1 -> match:case[2] -> ($secondLine2 -> println:data) 61 match:else -> [ 62 printf:args[0], 63 ($secondLine1 -> printf:tpl) 64 ] 65 66 [println:sig, printf:args[0]] -> lock:sig 67 lock:data -> :n 68 }