sharkdp / numbat

A statically typed programming language for scientific computations with first class support for physical dimensions and units
https://numbat.dev
Apache License 2.0
1.25k stars 52 forks source link

[Design] Multiline expression #539

Open irevoire opened 3 months ago

irevoire commented 3 months ago

Hey,

At the end of https://github.com/sharkdp/numbat/pull/519 you said:

The lookahead would also be useful for common expressions like

let my_result = some * complicated * terms
                + more * complicated * stuff

where the `+' is on the next line. But not sure if that's really possible to do with the current mechanism.

And I think that would be really nice so I’m just opening an issue to keep track of it. For example converting:

fn _human_readable_duration(time: Time, dt: DateTime, num_days: Scalar) -> String =
    _human_days(_human_num_days(time)) |> _human_join(_human_hours(dt)) |> _humain_join(_human_minutes(dt)) |> _human_join(_human_seconds(dt))

to

fn _human_readable_duration(time: Time, dt: DateTime, num_days: Scalar) -> String =
    _human_days(_human_num_days(time))
      |> _human_join(_human_hours(dt))
      |> _human_join(_human_minutes(dt))
      |> _human_join(_human_seconds(dt))
sharkdp commented 3 months ago

Thank you for writing it down. It's probably good to do some research into what other programming languages (without semicolon-terminated statements) do, before we implement this. For example: Python requires \-escaped newlines in some cases (when?).

It probably helps that we decided to use introducer-keywords like let or fn in Numbat. Otherwise, it would be hard to decide what something like this is:

some * terms +

my_variable = 2
irevoire commented 2 months ago

Huum just a though but maybe that’s not that big of a deal if we provide a formatter (especially since numbat already sends you back what it understood of your statement). But yeah, I would say that while we continue to use introducer-keywords, we should be good.