Proposal: Allow a training `=` on any var infix fu...
# language-proposals
r
Proposal: Allow a training
=
on any var infix function that returns the receiver's type (or compatible):
Copy code
// Current
var superAwesomeNumber = 5
superAwesomeNumber = superAwesomeNumber shl 3

// New
var superAwesomeNumber = 5
superAwesomeNumber shl= 3
It would be nice for long chains of bitwise operators, but it could also be nice for any infix function. It is especially appealing when you use very descriptive names.
👍 4
👎 3
This is similar to an earlier proposal of allowing
!
prefix on any infix function that returns Boolean, but I'm not sure what happened with that proposal.
o
Any other use cases besides shifting?
It applies only to infix functions that have their receiver of the same type as return type (or compatible in some way)
h
I'd rather see real bitwise operators 😀
or=
and
and=
would also be use cases
👍 3
r
@orangy Sure. All the bitwise operators
layers and= mask
,
flags or= newFlag
. I also have some custom number infix functions it would be nice to use like
currentInnerRatio pMod= 9.0
and
colorOffset pingPong= upperBound
@hudsonb I agree, but this could apply to more than just bitwise. I just happend to be using a lot of them at the moment 🙂
Like many of my proposals, I haven't thought through all the edges, so I'm not sure if this is a good idea overall. One possible problem would be that you couldn't easily override it like you can with operators (
+=
,
-=
, etc.), so it may feel a little incongruous.
@orangy
It applies only to infix functions that have their receiver of the same type as return type (or compatible in some way)
Indeed, that's what I meant by "variable's type". I've updated it.
d
I have a hard time visually parsing
superAwesomeNumber shl= 3
as something other than
(superAwesomeNumber shl)= 3
so I think if this proposal is accepted I’d like to make sure that the syntax highlighting is distinct in the IDE.
👍 2
e
still much better
superAwesomeNumber <<= 3
2
I find it much faster to read because it's not literal
r
@elect I agree, but this proposal has nothing to do with bitwise operators. That is a separate proposal that had been in discussion for quite a while.