Skip to content

Infix operators — and & or vs && & || #2170

Closed

Description

@max-sixty

What's up?

Do we want to keep and & or and infix operators?

Currently there's almost a clear split:

  • Symbols, such as +, *, are all infix — i.e. they go between operands, 5 + 8, 4 * 3
    • Some are prefix, such as ! or - when they're unary
  • Functions are all prefix — i.e. they go before operands — i.e. sum foo, in 5..10 bar
    • And then the pipe symbol lets them go after operands — i.e. foo | sum, bar | in 5..10, which is how we normally use them

...except for and & or, which are infix.

So we could instead use && and || for these. That's a bit "techie" for my liking, but the consistency would be good.

Activity

  1. added
    language-design
    needs-discussion
    on Mar 14, 2023
  2. aljazerzen commented on Mar 14, 2023

    @aljazerzen
    Member

    You make a good point. I agree with the distinction.

    Unfortunately it impacts "easy" queries:

    from albums
    filter albums_id == 1 || albums_id == 2
    

    It would feel closer to c-style notation, but a bit less approachable for non-tech-savy people.

    I'm +0.5

  3. eitsupi commented on Mar 14, 2023

    @eitsupi
    Member

    I like && & ||, rather than and & or (#1964 (comment))

    But, there are |, || and &&, but no &... I think it could be confusing.
    Nevertheless, is it not a problem if the appropriate errors are made? (like maybe `&&`?)

  4. max-sixty commented on Mar 19, 2023

    @max-sixty
    MemberAuthor

    As discussed on the dev call, let's go ahead!

  5. added
    good first issue
    on Mar 23, 2023
  6. max-sixty commented on Mar 23, 2023

    @max-sixty
    MemberAuthor

    Marking this as Good First Issue — the code changes are fairly isolated to the parser, which is the simplest part of the compiler. Almost a search replace for and & or -> && & || would be sufficient (but I imagine not quite...)

    Possibly lezer would need some small amount of work to ensure it can handle & and &&, but if someone were to do the work for this, I'd be happy to make those changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issuelanguage-design

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions