nevalang / neva

🌊 Flow-based programming language with static types and implicit parallelism. Compiles to native code and Go
https://nevalang.org
MIT License
85 stars 7 forks source link

Alternative `nodes` syntax #658

Open emil14 opened 1 month ago

emil14 commented 1 month ago

Replace nodes{} with node ... just like we did when we removed group form in #601

It will save as 2 lines and 1 nesting level, but will allow to mix nodes and connections (could be handled by formatter/linter)

Before

component Main(start) (stop) {
  nodes {
    r1 Range, r1 Range
    Product<int, int>,
    For<ProductRes<int, int>>{Println<ProductRes<int, int>>}
  }
  :start -> [
    (0 -> [r1:from, r2:from]),
    (3 -> [r1:to, r2:to])
  ]
  r1 -> product:first
  r2 -> product:second
  product -> for -> :stop
}

After

component Main(start) (stop) {
  node r1 Range, r2 Range
  node Product<int, int>
  node For<ProductRes<int, int>>{Println<ProductRes<int, int>>}

  :start -> [
    (0 -> [r1:from, r2:from]),
    (3 -> [r1:to, r2:to])
  ]
  r1 -> product:first
  r2 -> product:second
  product -> for -> :stop
}

Downside

It would be impossible to reuse this syntax recursevely for DI

emil14 commented 1 month ago

With comp instead of component

comp Main(start) (stop) {
  node r1 Range, r2 Range
  node Product<int, int>
  node For<ProductRes<int, int>>{Println<ProductRes<int, int>>}

  :start -> [
    (0 -> [r1:from, r2:from]),
    (3 -> [r1:to, r2:to])
  ]
  r1 -> product:first
  r2 -> product:second
  product -> for -> :stop
}