Skip to content

Tracking issue: If/else (ternary operator) #696

@casey

Description

@casey

I propose adding an if construct, restricted by the parser to equality tests:

foo := if A == B { THEN } else { ELSE }

A, B, THEN, and ELSE are all arbitrary expressions. If A equal to B then it will evaluate as THEN, otherwise it will evaluate as ELSE.

The reason I propose adding if, restricted to equality testing, instead of a more general if, is because if, in some future in which Just get's a type system, I would like the condition, A == B above, of if to be a bool. By restricting if to equality testing, a future enhancement which adds boolean and relaxes `if's condition to be any expression would not be a breaking change.

I added the good first issue tag to this. It's tough, but I think doable for someone that's interested in learning how the lexer and parser work. The only complication I see is making sure that if isn't always parsed as a keyword, so that having a recipe named if doesn't become an error.

(See prior discussion in #262 and #674.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions