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" {...@@ -3,10 +3,8 @@ test "ambiguous precedence" {
3 const y: u8 = 2;3 const y: u8 = 2;
4 const z: u8 = 3;4 const z: u8 = 3;
5 5
6 // Its not obvious below if this is multiplication by a masked value6 // 1. Could be multiplication by a masked value: (x&y) *% z
7 // `(x&y) *% z`7 // 2. Or masking the result of multiplication: x & (y*%z)
8 // or a masking of wrapped multiplication
9 // `x & (y*%z)`
10 _ = x & y *% z;8 _ = x & y *% z;
11}9}
1210
doc/langref/ambiguous_precedence_orelse_ne.zig+3-6
...@@ -9,12 +9,9 @@ test "ambiguous precedence" {...@@ -9,12 +9,9 @@ test "ambiguous precedence" {
9 const y: u8 = 0;9 const y: u8 = 0;
10 const z: u8 = 0;10 const z: u8 = 0;
11 11
12 // We might expect the line below to parse something like:12 // Without parentheses the compiler cannot distinguish between two conflicting interpretations:
13 // `makeBool(x) orelse (y != z)`13 // 1. Compare on the value which may be recovered: (makeBool(x) orelse y) != z
14 // but we might elsewhere want something like 14 // 2. Recover to the result of the comparison: makeBool(x) orelse (y != z)
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
18 _ = makeBool(x) orelse y != z;15 _ = makeBool(x) orelse y != z;
19}16}
2017
doc/langref/ambiguous_precedence_shift_sub.zig+2-2
...@@ -2,8 +2,8 @@ test "ambiguous precedence" {...@@ -2,8 +2,8 @@ test "ambiguous precedence" {
2 const x: u64 = 1;2 const x: u64 = 1;
3 const y: u6 = 63;3 const y: u6 = 63;
4 4
5 // We probably meant `(x << y) - 1`5 // 1. Could mean shift then subtract: (x<<y) - 1 such as to generate a mask
6 // But thats not how it would have compiled6 // 2. Or to shift after the subtract: x << (y-1) such as selecting bits
7 _ = x << y - 1;7 _ = x << y - 1;
8}8}
99
doc/langref/operator_precedence.zig+5-6
...@@ -5,20 +5,19 @@ test "operator precedence" {...@@ -5,20 +5,19 @@ test "operator precedence" {
5 const y = 2;5 const y = 2;
6 const z = 3;6 const z = 3;
77
8 // Because comparisons have a lower precedence than any arithmetic
9 // We can safely avoid parenthesizing the expressions
10 assert(x + y * z == x + (y*z));8 assert(x + y * z == x + (y*z));
11 assert(x * y + z == (x*y) + z);9 assert(x * y + z == (x*y) + z);
12 10
13 // We can also use ambiguous operators as long as they are seperated11 // Ambiguously related operators may exist in the same expression if they are not adjacent
14 // by a well ordered one such as below
15 assert(x*y + x%y == (x*y) + (x%y));12 assert(x*y + x%y == (x*y) + (x%y));
16 //That includes comparisons13 // Thus includes comparisons
17 assert(x & y != x + y);14 assert(x & y != x + y);
1815
19 // We can freely chain or's and and's, but not with each other16 // Or's and and's may be freely chained, but not with each other
20 assert(false or x == y or x + y == z);17 assert(false or x == y or x + y == z);
21 assert(true and x != y and y != z);18 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);
22}21}
2322
24// test23// test
\ No newline at end of file