4 ms·
``` for (monster_elem_types, monster_hps) |et, hp| { if (et == .fire) hp. +|= 1; // saturating addition } ``` Anyone knows what language Zig was inspired b
by halayli 4y ago
```
for (monster_elem_types, monster_hps) |et, hp| {
if (et == .fire) hp. +|= 1; // saturating addition
}
```
Anyone knows what language Zig was inspired by(if any)? This doesn't look intuitive nor does it resemble any common syntax.
- edflsafoiewq 4y ago|x| for captures is from Ruby. Special ops are formed by adding another symbol onto an operator: wrapping ops are +% -% etc, saturating ops are +| -| etc. This pattern was perhaps inspired by OCaml, which uses +. -. etc for floating point ops. The | for saturating is because "| looks like a wall". The <op>= syntax is of course from C. p.* is pointer deference. It was probably chosen for parsing reasons. The * is C for dereference, the . prevents ambiguity with multiplication. It may have been inspired by the postfix p^ from Pascal. The .fire is just MyEnumType.fire with MyEnumType omitted; the type will be inferred.