nevalang / neva

🌊 Dataflow programming language with static types and implicit parallelism. Compiles to machine code and Go
https://nevalang.org
MIT License
128 stars 8 forks source link

HOCs as desugared base for "controlflow" constructs ("Closure" Problem) #739

Open emil14 opened 3 weeks ago

emil14 commented 3 weeks ago

Related to #724

There're (probably) no problems with things like ternary/binary/cond/if-else/etc - components that we wanna support at syntax level, that are NOT implemented as HOCs.

On the other hands there are things like For(Each), etc. They have dependencies. Let's imagine this kind of syntax for #687

def Foo(foo stream<int>, bar any) (sig any) {
    :foo -> for {
        // accessing :bar from here
        data -> ...
        idx -> ...
        last -> ...
    } -> :sig
}

For(Each) is a component that takes dependency and DI in Nevalang is not inline (see #720 for details). This mean that we don't have closures. In other words we can't access :bar from inside for loop here. Same goes for switch, match, etc. All syntax features that implemented as HOCs under the hood.

emil14 commented 3 weeks ago

Restrict Closures

Simplest solution is to check that all port-addresses that we use are (in this case) data, idx and last.

Problem

The power of for-loop construct in C-like languages comes with being able to access outside scope and early termination with break, both of these features are not implemented in this. This is more problem of #687 issue but not having closures might be confusing

emil14 commented 3 weeks ago

Could ForEach (or it's alternative?) be implemented not as a HOC?

emil14 commented 2 weeks ago

might be related to #627