enso-org / enso

Hybrid visual and textual functional programming.
https://enso.org
Apache License 2.0
7.34k stars 320 forks source link

if then else and chained block syntax #8489

Closed JaroslavTulach closed 6 months ago

JaroslavTulach commented 9 months ago

Assuming that

    main =
        pairs = (if t then a else b) . to_vector . sort

and

    main =
        pairs = if t then a else b
            . to_vector
            . sort

shall be the same. They are not right now on 2023.2.1-nightly.2023.12.7

somebody1234 commented 9 months ago

@JaroslavTulach i think you messed up the link?

JaroslavTulach commented 9 months ago

@kazcw what do you think? As far as I can see in debugger the chained code is equivalent to b . to_vector . sort - e.g. the chain is only applied to the b and not to the result of the whole if_then_else.

JaroslavTulach commented 9 months ago

There are three tests. Two work, but testIfAndBlockSyntax fails. Is that correct or wrong, @kazcw?

kazcw commented 9 months ago

I'm looking for a consistent rule that would make this work. Here's a candidate:

The body of an else segment is either:

This is a change from current behavior, in which if the else has in-line content, any following child block belongs to the else branch.

This would also affect other block types, e.g. this:

    main =
        value = if t then f1 else f2
            y

Would be equivalent to this:

    main =
        value = (if t then f1 else f2)
            y

IMO it minimizes confusion to treat all block types the same way in this regard.

What do you think, @JaroslavTulach? If we shall do it, I can use the AST-comparison script to check for any existing code relying on the old behavior.

JaroslavTulach commented 9 months ago

The rest of the line (if non-empty) A following child block (if there is no expression following the else on the same line)

+1

enso-bot[bot] commented 6 months ago

Jaroslav Tulach reports a new STANDUP for yesterday (2024-02-21):

Progress: - rust parser: https://github.com/enso-org/enso/pull/8671/files#r1497057518

Next Day: Rust parser, Extension methods for Java

GitHub
Chained if_then_else application change by JaroslavTulach · Pull Request #8671 · enso-org/enso
Pull Request Description Attempt to fix #8489 by adding test describing current behavior: c5bef79 another test showing desired Group-like behavior: 1c722f4 changing the first test to behave like t...
enso-bot[bot] commented 6 months ago

Jaroslav Tulach reports a new STANDUP for yesterday (2024-02-22):

Progress: - chained if_then_else re-review: https://github.com/enso-org/enso/pull/8671#pullrequestreview-1894921442

Next Day: Extension methods for Java

enso-bot[bot] commented 6 months ago

Jaroslav Tulach reports a new STANDUP for yesterday (2024-02-23):

Progress: - bookclubbing

Next Day: Extension methods for Java