by smithza · 6y ago · 0 comments
onchange(x){ doSomething()}//on change of x, perform an action
every(x){ doSomething(x)}//as above but including initial value
await(x; x > 2)//pause execution until the condition is met
trans{//a transaction acting upon two references
a -= 10
b += 10
}
z <= a+b//shorthand for every
z <- a+b//shorthand for onchange
Is this novel to abstract languages? Would something like this work in a language without a VM like C++?I imagine needing registrations of these conditionals in the VM to watch and execute.
As far as languages go, the ideas you showed look similar to how Esterel[3] works, or perhaps Occam[4].
[2] https://github.com/hoplon/javelin
[3] https://en.wikipedia.org/wiki/Esterel
[4] https://en.wikipedia.org/wiki/Occam_(programming_language)
For background reading in this area, perhaps start with "A poor man's concurrency Monad" by Claessen, it's a very easy read and shows how green threads can be written as a user library allowing pluggable schedulers. F# also implements its asynchronous workflows using essentially this technique, see "The F# Asynchronous Programming Model". LINQ and the reactive library Rx from C# are also great examples of Monads.