authorgravatar for gbell12907@gmail.comCMDRZero <gbell12907@gmail.com> 2026-07-14 23:48:51-05:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-22 12:21:43+02:00
log1bae04f02026427d1754f704bd24fce3317f3e89
tree67ecdb6e49e44b791efc7adf7f313e27a544c7c8
parent2d3eece3f4c6ab67165aab2c6c0bc890ad2338ea

Many tweaks to the langref to improve style, clarity, and make me sound less wierd.


4 files changed, 12 insertions(+), 18 deletions(-)

doc/langref/ambiguous_precedence_mul_bitand.zig+2-4
......@@ -3,10 +3,8 @@ test "ambiguous precedence" {
33 const y: u8 = 2;
44 const z: u8 = 3;
55
6 // Its not obvious below if this is multiplication by a masked value
7 // `(x&y) *% z`
8 // or a masking of wrapped multiplication
9 // `x & (y*%z)`
6 // 1. Could be multiplication by a masked value: (x&y) *% z
7 // 2. Or masking the result of multiplication: x & (y*%z)
108 _ = x & y *% z;
119}
1210
doc/langref/ambiguous_precedence_orelse_ne.zig+3-6
......@@ -9,12 +9,9 @@ test "ambiguous precedence" {
99 const y: u8 = 0;
1010 const z: u8 = 0;
1111
12 // We might expect the line below to parse something like:
13 // `makeBool(x) orelse (y != z)`
14 // but we might elsewhere want something like
15 // `(nullable(x) orelse y) != w`
16 // to perform a fallback and then a check, either way its
17 // not obvious the behavior so we get an error
12 // Without parentheses the compiler cannot distinguish between two conflicting interpretations:
13 // 1. Compare on the value which may be recovered: (makeBool(x) orelse y) != z
14 // 2. Recover to the result of the comparison: makeBool(x) orelse (y != z)
1815 _ = makeBool(x) orelse y != z;
1916}
2017
doc/langref/ambiguous_precedence_shift_sub.zig+2-2
......@@ -2,8 +2,8 @@ test "ambiguous precedence" {
22 const x: u64 = 1;
33 const y: u6 = 63;
44
5 // We probably meant `(x << y) - 1`
6 // But thats not how it would have compiled
5 // 1. Could mean shift then subtract: (x<<y) - 1 such as to generate a mask
6 // 2. Or to shift after the subtract: x << (y-1) such as selecting bits
77 _ = x << y - 1;
88}
99
doc/langref/operator_precedence.zig+5-6
......@@ -5,20 +5,19 @@ test "operator precedence" {
55 const y = 2;
66 const z = 3;
77
8 // Because comparisons have a lower precedence than any arithmetic
9 // We can safely avoid parenthesizing the expressions
108 assert(x + y * z == x + (y*z));
119 assert(x * y + z == (x*y) + z);
1210
13 // We can also use ambiguous operators as long as they are seperated
14 // by a well ordered one such as below
11 // Ambiguously related operators may exist in the same expression if they are not adjacent
1512 assert(x*y + x%y == (x*y) + (x%y));
16 //That includes comparisons
13 // Thus includes comparisons
1714 assert(x & y != x + y);
1815
19 // We can freely chain or's and and's, but not with each other
16 // Or's and and's may be freely chained, but not with each other
2017 assert(false or x == y or x + y == z);
2118 assert(true and x != y and y != z);
19 // The following line would be a compile error
20 // assert(false or x != y and y != z);
2221}
2322
2423// test
\ No newline at end of file