DEV Community

Discussion on: Help design a language: What about tuples without commas?

Collapse
 
nestedsoftware profile image
Nested Software • Edited

Will this approach work okay with cases where the items are themselves multi-line expressions? That's the first question/concern that comes to mind.

This brings to mind the ; in JavaScript, where it can now be omitted at the end of a line. I haven't actually tried (besides for loops) but I assume you'd still need it if you want to have multiple statements on a single line. I don't know if it is equivalent though.

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

Expressions in Leaf don't extend beyond a line unless they belong to an open pair, such as (), {}, or [].

For example, this is invalid:

var a = 5 +
   7

Single item value-lists can be used to extend beyond a line:

var a = (5 +
   7)

This will work inside tuples as well, in cases where you need extra formatting:

var items = [
   one
   (some_condition ?
       first_value |
       second_value
   )
   third
]

I'll be encouraging a style that discourages such inline complexity. Given that types are inferred anyway, it's usually not much of a problem to do this instead:

var two = (some_condition ?
   first_value |
   second_value
)

var items = [
   one
   two
   third
]

I'm not a big fan of cramming too much into a single expression as it makes the code harder to follow.

There'll potentially also be a let syntax:

let two = (some_condition ?
   first_value |
   second_value
)

var items = [
   one
   two
   third
]

I'm thinking of making this a kind of lazy-evaluation that doesn't actually introduce a real variable.