Closed emil14 closed 1 month ago
component Main(start) (stop) {
nodes { Match<int>, next PrintNext2Lines }
:start -> (99 -> next -> match:data)
-1 -> match:case[0] -> :stop
match:else -> next
}
component PrintNext2Lines(n int) (n int) {
nodes {
decr Decr<int>
first PrintFirstLine
second PrintSecondLine
}
:n -> first -> decr -> second -> :n
}
// === First Line ===
const {
firstLine1 string = '$0 bottles of beer on the wall, $0 bottles of beer.\n'
firstLine2 string = '1 bottle of beer on the wall, 1 bottle of beer.'
firstLine3 string = 'No more bottles of beer on the wall, no more bottles of beer.'
}
component PrintFirstLine(n int) (n int) {
nodes { Match<int>, Println, Printf, Lock<int> }
:n -> [match:data, lock:data]
0 -> match:case[0] -> ($firstLine3 -> println)
1 -> match:case[1] -> ($firstLine2 -> println)
match:else -> [
printf:args[0],
($firstLine1 -> printf:tpl)
]
[println, printf:args[0]] -> lock:sig
lock -> :n
}
// === Second Line ===
const {
secondLine1 string = 'Take one down and pass it around, $0 bottles of beer on the wall.\n\n'
secondLine2 string = 'Take one down and pass it around, 1 bottle of beer on the wall.\n'
secondLine3 string = 'Take one down and pass it around, no more bottles of beer on the wall.\n'
secondLine4 string = 'Go to the store and buy some more, 99 bottles of beer on the wall.'
}
component PrintSecondLine(n int) (n int) {
nodes { Match<int>, Println, Printf, Lock<int> }
:n -> [match:data, lock:data]
-1 -> match:case[0] -> ($secondLine4 -> println)
0 -> match:case[1] -> ($secondLine3 -> println)
1 -> match:case[2] -> ($secondLine2 -> println)
match:else -> [
printf:args[0],
($secondLine1 -> printf:tpl)
]
[println, printf:args[0]] -> lock:sig
lock:data -> :n
}
comp Main(start) (stop) {
nodes { Match<int>, next PrintNext2Lines }
:start -> (99 -> next -> match:data)
-1 -> match:case[0] -> :stop
match:else -> next
}
comp PrintNext2Lines(n int) (n int) {
nodes {
decr Decr<int>
first PrintFirstLine
second PrintSecondLine
}
:n -> first -> decr -> second -> :n
}
// === First Line ===
const {
firstLine1 string = '$0 bottles of beer on the wall, $0 bottles of beer.\n'
firstLine2 string = '1 bottle of beer on the wall, 1 bottle of beer.'
firstLine3 string = 'No more bottles of beer on the wall, no more bottles of beer.'
}
comp PrintFirstLine(n int) (n int) {
nodes { Match<int>, Println, Printf, Lock<int> }
:n -> [match:data, lock:data]
0 -> match:case[0] -> ($firstLine3 -> println)
1 -> match:case[1] -> ($firstLine2 -> println)
match:else -> [
printf:args[0],
($firstLine1 -> printf:tpl)
]
[println, printf:args[0]] -> lock:sig
lock -> :n
}
// === Second Line ===
const {
secondLine1 string = 'Take one down and pass it around, $0 bottles of beer on the wall.\n\n'
secondLine2 string = 'Take one down and pass it around, 1 bottle of beer on the wall.\n'
secondLine3 string = 'Take one down and pass it around, no more bottles of beer on the wall.\n'
secondLine4 string = 'Go to the store and buy some more, 99 bottles of beer on the wall.'
}
comp PrintSecondLine(n int) (n int) {
nodes { Match<int>, Println, Printf, Lock<int> }
:n -> [match:data, lock:data]
-1 -> match:case[0] -> ($secondLine4 -> println)
0 -> match:case[1] -> ($secondLine3 -> println)
1 -> match:case[2] -> ($secondLine2 -> println)
match:else -> [
printf:args[0],
($secondLine1 -> printf:tpl)
]
[println, printf:args[0]] -> lock:sig
lock:data -> :n
}
Yeah, every language seems to choose an id for this <= 4 characters. (func, def, fun, etc...). I think it's worth doing.
Other possible short words are unit
, node
, elem
, part
, com
but they may be harder to get used to. comp
does make sense in context.
I like unit
and (a little less) elem
.
I was also thinking about def
. In Python it stands for "define" and defines function. It could be used to define components as well.
Another option could be to use word "module"
module Main(start) (stop) {
// ...
}
or
mod Main(start) (stop) {
// ...
}
Ofc we'll have to rename Neva's modules (that are same as Go's modules) to something else. Projects?
Another option I like is to use the word "process" instead of component. It describes perfectly what we call a component, we process the data with them.
This could be shortened nicely to
proc Main(start) (stop) {
// ...
}
In JS we have
function
but in Go it'sfunc
, in Kotlin it'sfun
and in Rust it's justfn
. I'm wondering if there's a language where it's justf
.Anyway. Should we shorten
component
? It's 9 characters, even bigger than "function". How aboutcomp
? That's probably the only way I can see it. It sounds also like acomputer
which also makes sense to me. Components is what does computation so it's a computer, yeah.