I realize what I am asking is "Dark magic" and goes against what should be done. However, with that in mind I would like to create a custom assignment operator.
var x:int =5
vs.
var x <| 5
or
var x << 5
What I have tried so far...
template `<<` (a, b: untyped): untyped =
system.`=`(a, b)
var a:int
a << 5
echo a
The above code works but,
var a << 5
But the error I get back is:
index.nim(9, 11) Error: type mismatch: got <type int, int literal(5)>
but expected one of:
proc `=`[T](dest: var T; src: T)
first type mismatch at position: 1
required type: var T
but expression 'int' is of type: type int
expression: `=`(int, 5)
Hope this is possible but honestly not sure. Mind you im only barely getting into Nim so expect some really dumb questions :/
Try with Source Code Filters
#? replace(sub="<<", by="=")
var a << 5
echo a
But that's an ugly hack. 😊
Everything that's a << becomes =, so echo "This is <<" outputs This is = .