In general, control flow is done with keywords and not sigils. || is actually closer to if than |.
However since we will be using keywords for boolean operators in this way, it seems fitting to use not instead of !. It is a little awkward that != is still "not equal" and is the only use of ! as "not" but maybe that's ok.
This frees up ! to be used as the error sigil instead of %.
Thanks to @ant6n for the suggestion.
I'd keep it consistent. a != b and not (a == b) being equivalent is a little weird. And what's to stop us from changing every operator to a keyword? Why not a equals b or a doesntequal b? a plus b where does it stop? Having keywords only in control flow is inconsistent.
I also like the use of % for errors, but that's just my opinion.
Fwiw, python uses not and != like this issue proposes. there is no ! operator in python, but ! still shows up in !=.
Other operators I've seen for "does not equal" (often attempting to emulate ≠in ascii) are /=, <>, and =/=. I think those are all bad alternatives, mostly for being uncommon, and <> is bad because the idea is that the two things are either greater or less than each other, which is not always true. != has the advantage of being immediately recognizable to any programmer who's the least bit familiar with popular programming languages.
regarding language constructs being words instead of symbols, there are two obvious places to draw the line. One is with statements vs expressions (this is what C does), and one is with control flow vs functions (this is what Python does). Control flow means you can't replace the language construct with a function without changing the semantics. Statements vs expressions is a syntax concept that I don't think I need to explain (even though I would be happy to if anyone asks).
if, while, for, switch, break, continue, return, goto: these are control flow constructs that are statements in C and expressions in Zig. I don't think there's much opposition to keeping these as words.&&, ||: these are control flow constructs that are expressions in both C and Zig. For reference, C also has the ?: ternary operator which is a control flow expression; Zig just uses if expressions for that.&, |, ~, ^, !, ==, !=, <, >, +, /, etc.: These are all "functions" in the mathematical sense, where they take their input(s) and produce an output. All inputs are fully evaluated before these "functions" run, so there's no control flow here.It's worth noting that not is not a control flow construct. It is a "boolean operator" as the OP suggests, but that concept isn't very meaningful. I suppose that means its input is a boolean and its output is a boolean. There are other operators whose inputs are anything and whose output is a boolean (==, <, etc.). Are those "boolean operators"? Idk, I don't like the "boolean operator" categorization. I think control flow vs function is less arbitrary.
Having keywords only in control flow is inconsistent.
Sure, technically. But that kind of reasoning could lead you to say that having multiple different operator precedences is inconsistent, or really any bit of complexity in a language is inconsistent. I don't think the kind of consistency you're describing is a design goal for Zig. The most consistent syntax I've ever seen is Lisp, but I don't think we want that much consistency.
@thejoshwolfe Thanks for this analysis. I did only the and and or change for now. Are you ultimately in favor of changing ! to not and changing % to ! for the error sigil?
Most helpful comment
Fwiw, python uses
notand!=like this issue proposes. there is no!operator in python, but!still shows up in!=.Other operators I've seen for "does not equal" (often attempting to emulate
â‰in ascii) are/=,<>, and=/=. I think those are all bad alternatives, mostly for being uncommon, and<>is bad because the idea is that the two things are either greater or less than each other, which is not always true.!=has the advantage of being immediately recognizable to any programmer who's the least bit familiar with popular programming languages.regarding language constructs being words instead of symbols, there are two obvious places to draw the line. One is with statements vs expressions (this is what C does), and one is with control flow vs functions (this is what Python does). Control flow means you can't replace the language construct with a function without changing the semantics. Statements vs expressions is a syntax concept that I don't think I need to explain (even though I would be happy to if anyone asks).
if,while,for,switch,break,continue,return,goto: these are control flow constructs that are statements in C and expressions in Zig. I don't think there's much opposition to keeping these as words.&&,||: these are control flow constructs that are expressions in both C and Zig. For reference, C also has the?:ternary operator which is a control flow expression; Zig just usesifexpressions for that.&,|,~,^,!,==,!=,<,>,+,/, etc.: These are all "functions" in the mathematical sense, where they take their input(s) and produce an output. All inputs are fully evaluated before these "functions" run, so there's no control flow here.It's worth noting that
notis not a control flow construct. It is a "boolean operator" as the OP suggests, but that concept isn't very meaningful. I suppose that means its input is a boolean and its output is a boolean. There are other operators whose inputs are anything and whose output is a boolean (==,<, etc.). Are those "boolean operators"? Idk, I don't like the "boolean operator" categorization. I think control flow vs function is less arbitrary.Sure, technically. But that kind of reasoning could lead you to say that having multiple different operator precedences is inconsistent, or really any bit of complexity in a language is inconsistent. I don't think the kind of consistency you're describing is a design goal for Zig. The most consistent syntax I've ever seen is Lisp, but I don't think we want that much consistency.