Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if (and) with indented condition list #1090

Open
bbrk24 opened this issue Mar 6, 2024 · 3 comments
Open

if (and) with indented condition list #1090

bbrk24 opened this issue Mar 6, 2024 · 3 comments

Comments

@bbrk24
Copy link
Contributor

bbrk24 commented Mar 6, 2024

This gives a ParseError saying it expected a ::= where I have undefined:

        return if (and)
            upper.test exactOrAny.toString()
            lower.test exactOrAny.toString()
        then exactOrAny
        else undefined

If I oblige and change the last line to else ::= undefined, the result is not remotely what I wanted out of this expression (and in fact not valid TS):

        return (((a,b) => a&&b)?(
            upper.test(exactOrAny.toString()),
            lower.test(exactOrAny.toString())):void 0)
        then(exactOrAny)
        type else = undefined

I was hoping to get this:

return (upper.test(exactOrAny.toString()) && lower.test(exactOrAny.toString())) ? exactOrAny : undefined;
@edemaine
Copy link
Collaborator

edemaine commented Mar 6, 2024

Currently we forbid indented function application in an if condition, to avoid confusion with the usual "then" block. For example:

if foo
  bar
↓↓↓
if (foo) {
  bar
}
// NOT
if foo(
  bar
)

Perhaps we could make an exception when there's an explicit then. Meanwhile, you can wrap your condition in parentheses...

@bbrk24
Copy link
Contributor Author

bbrk24 commented May 6, 2024

Just ran into this in a different context:

return false unless (and)
  ...

@edemaine
Copy link
Collaborator

edemaine commented May 6, 2024

Ah, adding support for indented function application to postfix if/then should be easier to add. (...unless I'm missing some ambiguity...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants