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

Dict and List reading syntax #746

Open emil14 opened 2 weeks ago

emil14 commented 2 weeks ago

Problem

At and Get components are used for accessing list element and dict value respectfully. Here's how it looks (example with dict):

Get?
---
v -> get:dict
k -> get:key
get -> println

This is cumbersome compared to other languages. Can we introduce syntax sugar for this?

Proposal - v[k|i] syntax

  1. Make Get/At send Maybe instead of having 2 outports
  2. Introduce index/key reading syntax that is desugared to using Get and At (based on data-type used)
v[k] -> unwrap
unwrap:some -> println
unwrap:none -> panic
emil14 commented 1 week ago

Use match

In Rust match statement is used to handle Option and Result (it also have unwrap macro which causes panic). It's possible to imagine that with Maybe is used with match statement (will work same for lists):

match v[k] {
    some -> println
    none -> panic
}

Problems

  1. It's not clear how exactly match statement must work - is this special form or common use-case? How will it play with other "forms" (if any)?
  2. We have to use maybe for something that is not IO-specific, while it was stated before that for internal logic outports must be used (but maybe this is good case for maybe too?)
  3. If we end up not having Result but only Maybe it might be not clear for folks with Rust/Haskell/etc background why emptiness handling is different than error handling

Related to #747 #726 #751 #756

emil14 commented 1 week ago

Standalone syntax form

v[k] {
    some ->
    match ->
}

I don't like this because numbers of reasons

  1. Both selecting and routing must be supported, which means it would be nice to be able to use it with match/switch statements
  2. maybe type, regardless of whether this union or base type, is more universal - e.g. we can pass it to other components