Closure (Implement "visibility scope" via hierarchy of deferred connections)
emil14 opened this issue · 4 comments
In control flow languages we have concept of scope
a = foo()
b = bar()
baz(a)
The reason for that is that in a control-flow language you describe program as a sequence of things that happens one after another in a single thread. So when we print(a,b)
we sure both a and b exist and foo
and bar(a)
were computed. However, that's not the case for dataflow language
foo -> print
bar -> del
We send message from foo
to println
while knowing nothing about whether bar
already sent or not. There is a solution for that problem - locks.
foo -> lock:data
bar -> lock:sig
lock:data -> println
However, our program just got harder to understand. And the more complex control-flow we need, the more locks and related connections we gonna have.
Scope Proposal
foo -> (
bar -> (foo -> baz)
)
Right now this program considered invalid (see #501 for more). The idea is to change that by making compiler handle this in a specific way
bar -> lock1:data
foo -> [lock1:sig, lock2:data]
bar -> lock2:sig
lock2:data -> baz
Can this solve this fizzbuzz version's problem?
flow FizzBuzz(data int) (res string | int) {
nodes { h1 Helper, h2 Helper, h3 Helper }
:data -> h1:num
15 -> h1:den
h1:then -> ('FizzBuzz' -> :res)
h1:else -> (:data -> h2:num)
3 -> h2:den
h2:then -> ('Fizz' -> :res)
h2:else -> (:data -> h3:num)
5 -> h3:den
h3:then -> ('Buzz' -> :res)
h3:else -> (:data -> :res)
}
Question is do we really need deferred connections here
Could it be solved with FanOut
?