digitalmars.dip.ideas - opUnaryAssign
- Quirin Schroll (9/9) Jul 03 Index operators (e.g. `obj[i]`) have special overloads so that
- monkyyy (5/14) Jul 03 wouldnt `+obj=rhs` combined with "assignment returns" be
- Quirin Schroll (13/25) Jul 04 In the [expression
Index operators (e.g. `obj[i]`) have special overloads so that they hook assignment: `obj[i] = rhs` lowers to `obj.opIndexAssign(rhs, i)`. Why not back-port this to dereferencing? `*obj` lowers to `obj.opUnary!"*"`, which, to be assignable, must return by reference. Why not add `opUnaryAssign(string op)` which can hook, in principle, `+obj = rhs`, `-obj = rhs`, `~obj = rhs`, `*obj = rhs`, `++obj = rhs`, and `--obj = rhs` (of which I expect only `*obj = rhs` to be used regularly).
Jul 03
On Wednesday, 3 July 2024 at 10:43:14 UTC, Quirin Schroll wrote:Index operators (e.g. `obj[i]`) have special overloads so that they hook assignment: `obj[i] = rhs` lowers to `obj.opIndexAssign(rhs, i)`. Why not back-port this to dereferencing? `*obj` lowers to `obj.opUnary!"*"`, which, to be assignable, must return by reference. Why not add `opUnaryAssign(string op)` which can hook, in principle, `+obj = rhs`, `-obj = rhs`, `~obj = rhs`, `*obj = rhs`, `++obj = rhs`, and `--obj = rhs` (of which I expect only `*obj = rhs` to be used regularly).wouldnt `+obj=rhs` combined with "assignment returns" be ambiguous in some case? ~~idk why people use assignment returns, its incredibly backwards of sanity and im fuzzy on the syntax~~
Jul 03
On Wednesday, 3 July 2024 at 13:26:35 UTC, monkyyy wrote:On Wednesday, 3 July 2024 at 10:43:14 UTC, Quirin Schroll wrote:In the [expression grammar](https://dlang.org/spec/expression.html), clearly `+obj` has precedence over `=`. The precedence table is [here](https://wiki.dlang.org/Operator_precedence). The gist is: 1. Postfix operators (includes call `()`, index `[]`, and member access `.`) 2. Prefix operators 3. Binary operators There are exceptions, e.g. binary `!` for templates is top, `^^` is stronger than unary prefix, and `=>` has different precedence on the left and right, but for the most part, the 3-item list is accurate.Index operators (e.g. `obj[i]`) have special overloads so that they hook assignment: `obj[i] = rhs` lowers to `obj.opIndexAssign(rhs, i)`. Why not back-port this to dereferencing? `*obj` lowers to `obj.opUnary!"*"`, which, to be assignable, must return by reference. Why not add `opUnaryAssign(string op)` which can hook, in principle, `+obj = rhs`, `-obj = rhs`, `~obj = rhs`, `*obj = rhs`, `++obj = rhs`, and `--obj = rhs` (of which I expect only `*obj = rhs` to be used regularly).wouldnt `+obj=rhs` combined with "assignment returns" be ambiguous in some case?
Jul 04