4 ms·
This feature is not so bad: > In case you really need to vary a variable, the when keyword lets you check a variable each time it mutates. const var health
by pmontra 3y ago
This feature is not so bad:
> In case you really need to vary a variable, the when keyword lets you check a variable each time it mutates.
const var health = 10!
when (health = 0) {
print("You lose")!
}
If it can really be triggered when the variable changes to any value it makes it a truly reactive paradigm programming language. By the way, could that be hacked to implement loops?
const var i = 10
when (i >= 0) {
do_something()
i = i - 1
}
- ilaksh 3y agoYeah honestly I was really interested in that. Kind of like a logic language? Maybe Prolog is the perfect language.
- epistasis 3y agoI like this feature, but to really make it pop I would like it to be combined with comefrom control flow.
- pmontra 3y agoYes, when is the way to do loops in this language. From the hidden examples page functi fibonacci (n) => { const var sum = 1! const var i = 0! when (i < n) { sum += sum + previous sum! i++! } } when (i < 10) { fibonacci(i)? i++! }
- ravi-delia 3y agoAnd if you don't want your code to loop back by accident you can just use lifetimes! Truly an elegant language
- Doxin 3y agoOh please tell me you can specify the length of your loops in lines of code executed.
- ravi-delia 3y agovar var i<10> = 0!! var var i = false! when (i) { print(i)! i++! } I think this should print 0,1,2 and then stop, assuming checking the condition is a line of code, and that lifetimes are for lines executed and not just the syntax.
- hoosieree 3y agoLooks a little like FRP.
- mhd 3y agoDoesn't Tcl's "trace" feature do this?
- krackers 3y agoThis feels sort of like key-value observation in obj-c
- squeaky-clean 3y agoIt's basically a syntactic sugar on an Observer pattern but I like it. You would need a way to turn off 'when' observers. And I suppose it does couple the observer to the observable pretty tightly.
- SamBam 3y agoIt's pretty easy to turn off the when observers, simply `delete when`. Side-effect is that it will delete all the whens, so only use it if you need it!
- pmontra 3y agoDelete the observed variable? About coupling, an implementation could send state change events to a message bus and observers could subscribe only the events they care about.
- Jiro 3y agoIsn't that basically a computed COME FROM?