5 ms·
Never seen anything like this before in a programming language (VHDL/Verilog supports this sort of stuff of course): onchange(x){ doSomething()}//on change o
by smithza 6y ago
Never seen anything like this before in a programming language (VHDL/Verilog supports this sort of stuff of course):
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.
- dkersten 6y agoThere are some languages that do this, especially reactive languages and there are some libraries for other languages that work kinda like this, for example Rx[1] works kinda like this or maybe Clojure's Javelin[2]. You could make an Rx-like system that works somewhat like that in C++, or you could use coroutines or a task-based system like Intel TBB to implement something kinda like this. It of course wouldn't be a first-class thing like in Concurnas, but I reckon you could implement the basic idea. As far as languages go, the ideas you showed look similar to how Esterel[3] works, or perhaps Occam[4]. [1] http://reactivex.io/ http://reactivex.io/ [2] https://github.com/hoplon/javelin https://github.com/hoplon/javelin [3] https://en.wikipedia.org/wiki/Esterel https://en.wikipedia.org/wiki/Esterel [4] https://en.wikipedia.org/wiki/Occam_(programming_language) https://en.wikipedia.org/wiki/Occam_(programming_language)
- smithza 6y agoThanks for these. Looks like Esterel commonly compiles to C and I would imagine uses some features of pthreads along with task-based scheduling as you mentioned.
- fulafel 6y agoAlso https://en.wikipedia.org/wiki/Dataflow_programming https://en.wikipedia.org/wiki/Dataflow_programming has a list of 30+ languages.
- willtim 6y agoIn a language that supports Monads (e.g. Haskell or Scala), the above could be implemented as a library.
- artemonster 6y agocan you recommend something to read to be able to understand more parctically HOW to implement those with monads? thank you
- willtim 6y agoMonads are a pattern for sequential composition of effectful computations (i.e. statements). Some expessive languages, such as F#, Haskell and Scala support a special overloadable syntax for any arbitrary monad, therefore giving a fully programmable notion of statements. 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.
- jcelerier 6y agoThat's partly how Qt's QML works (which makes it a breeze for UI): https://doc.qt.io/qt-5/qtqml-syntax-propertybinding.html https://doc.qt.io/qt-5/qtqml-syntax-propertybinding.html
- edem 6y agoYou can do this in Kotlin if you want to. It comes with coroutines support out of the box. With things like Channel and select you could implement trans as well.
- fluffything 6y agoMost languages implement these as a library.