erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.61k stars 53 forks source link

Consider using indentation for line-continuation #478

Open buster-blue opened 5 months ago

buster-blue commented 5 months ago

Currently, it seems that the only way to continue a statement over multiple lines is to use the backslash character, like Python does. Another programming language that uses significant indentation is Ante, and it has an interesting alternative to backslashes. Instead, you can continue a line across multiple lines by indenting the following lines. So for example, in Erg, this expression:

1..100 \
|>.iter() \
|>.filter i -> i % 2 == 0 \
|>.collect Array

could instead by written as:

1..100
    |>.iter()
    |>.filter i -> i % 2 == 0
    |>.collect Array

Which I think looks much better, and it's also easier to see at a glance where the line continuations are happening, because they're visually grouped.

For what it's worth, Nim also appears to allow you to continue lines this way.

func increment(num: Natural): Natural = num + 1
let testNum: Natural = 0
let testNum2 = testNum
  .increment
  .increment

assert testNum2 == 2
mtshiba commented 5 months ago

This relates to https://github.com/erg-lang/erg/issues/393.