#64Separate operator for concatenation

  • avatar~Luyten-Orioncommented · 2 years ago
    Author

    Issue title is basically it, but my suggestion is to use + for arithmetic and & for concatenation operations, such as adding an item to a list or joining strings together, as in my opinion, it can reduce logic errors where someone is trying to treat user input as a number without first converting it


    Milestone: 0.3.0.

  • avatar~Luyten-Orion changed the status to Todo · 2 years ago
  • avatar~clovercommented · 2 years ago
    Owner

    note & is currently bitwise AND, so the same mistake can still be made. & is likely to become a prefix and postfix operator for reference related stuff (no issue open)

    other suggestions are ++ (alike zig) and .. (lua and php iirc). adding a new operator might be a good idea.

    when this is implemented in sema, the error for failed binary type resolution should add a note for the correct operator if both ends are strings.

  • avatar~lino-levancommented · 2 years ago

    I don't love a separate operator for concatenation. I'm pretty strongly in favor of just keeping it as +. If we had to have a concat operator, ++ would be my vote. I'm a little confused what the argument against + as concat is.

    Sidenote, we should avoid prefix operators if it all possible. - is fine, but I'd give any others a strong 🤨.

  • avatar~clovercommented · 2 years ago
    Owner

    just for reference the current list of prefix operators / planned prefix operators

    • -x (negation)
    • !x (bool not)
    • ~x (bitwise not)
    • []x (array type, in dev)
    • &x (reference type, planned)
    • ?x (optional type, planned)

    as it stands i don't want to introduce any more non-type prefix operators.

  • avatar~lino-levancommented · 2 years ago

    Unrelated to issue but: &x as a type is a +1 for me.

    x.&
    

    would be my preferred syntax for referencing a value. Given that we're discussing referencing, should we maybe move that discussion to a separate issue? I know you were initially against it but have potentially changed positions at this point.

  • avatar~clovercommented · 2 years ago
    Owner

    yeah, i am deferring that until i have the time to write up when and how data copying will work in regards to references.

    this issue seems to be blocked on more users trying to use the language, so we will defer until then.