3 ms·
The postfix versions of ++ and -- have no simple analogue. I propose fixing this: z = (a += 1) means z gets the new value of a, but z = (a +: 1) means z gets o
by jhallenworld 11y ago
The postfix versions of ++ and -- have no simple analogue. I propose fixing this: z = (a += 1) means z gets the new value of a, but z = (a +: 1) means z gets old value a, same as in z = a++.
Likewise, z = (a : 5), means that z gets old value of a, then a gets 5.
This makes for a nice family of operators. For example, to swap the contents of two variables you can say: a:b:a (or a=b:a). Also you can rotate through a bunch of variables: a:b:c:d:a transfers all the contents to the left, and puts the old value of a into d.
The . operator should have an assignment form as well, so that you can say: p .= next instead of p = p.next
Now you can traverse linked lists very concisely:
for (p = first; p; p .= next) serialize(p);
Of course .: will have the expected meaning: return old value of left side, then replace it with one of its members. So you can say:
while (p) serialize(p.:next)
- SamReidHughes 11y agoWhy do you want this?
- jhallenworld 11y agoSame reason mathematicians have symbols like: ∀, ∃, ∴, ∬, etc. In fact now that Unicode is universal we should use all of these operators too :-)