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

`Select` syntax sugar #728

Open emil14 opened 1 month ago

emil14 commented 1 month ago

See #724

Before (desugared)

flow GetString(a, b, c) (s string) {
    Select<string>
    ---
    :a -> select:if[0]
    :b -> select:if[1]
    :c -> select:if[2]

    'a' -> select:then[0]
    'b' -> select:then[1]
    'c' -> select:then[2]
    'd' -> select:else

    select -> :s
}

After (sugar)

def GetString(a, b, c) (s string) {
    select {
        :a: 'a'
        :b: 'b'
        :c: 'c'
        else: 'd'
    } -> :s
}
emil14 commented 3 weeks ago

This is not like Go's select

Go's select answers not just "where from" but also "what" (you can ignore value from chan but it's there)