Hey guys, I've been using the `dotOperators` feature since I started my game 
engine project 2 years ago. I use it to interface with C++ libraries, and for 
the most part it works amazingly. Being able to implicitly generate Nim 
bindings to a C++ library as you use it in your code is sick, IMO. I also use 
it to implement GLSL/HLSL-like field swizzling for my math stuff.

As useful as it is, I have encountered some limitations with it. `dotOperators` 
has `.=`, but it doesn't have something like `.+=`, or `.*=`, or `.<arbitrary 
operator>`. It would be cool to be able to do something like `vector4.yzx *= 
2`, and it doesn't seem like extending `dotOperators` to support this scales 
well.

I don't know anything about language design, but a thought occurred to me that 
might address this issue. Right now, Nim has computed properties using the 
`property=` syntax (would also be cool to have `property+=`, etc.). What if 
there was a special macro/template that could generate procs like this, without 
explicitly naming them? Something like:
    
    
    type Obj = object
    
    macro `=call`(obj: Obj, op: untyped, args: varargs[untyped]): untyped =
      echo op.repr
    
    let instance: Obj
    instance.test = 1 # prints 'test='
    instance.test += 1 # prints 'test+='
    discard instance.test # prints `test`
    `test*=`(instance, 1) # prints `test*=`; probably not feasible, have to 
mention anyway :)
    
    
    Run

I think this would cover all usages of `dotOperators` and add flexibility. If 
taken a bit further, it could replace the experimental `()` operator as well. I 
know Araq has been considering deprecating `dotOperators` and the `()` thing, 
and this could be viable replacement. What do you guys think? Is this idea 
super dumb or worth some/partial consideration?

Reply via email to