How to have Nim overloaded operator i.e. two operands infix operator ? e.g
` s .= function()` to mean s = s.function()
on:
std/nre
template `.=`( a :string; b :proc( m :untyped, n:untyped) ) =
var a :string = a.b
var
s="hello world !"
s .= replace(re"\w+", "masked")
echo s
fails with
..................Traceback from system (most recent call last)
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
------------------
(program exited with code: 1)
And other errors for other tried tiny variations
Sincerely, help out please
That being said you can make it work with a macro and a slightly different operator:
import std/nre, macros, sequtils
macro `:=`(a: var string; b: untyped): untyped =
var call = b
call.insert(1, a)
result = quote do:
`a` = `call`
echo result.repr
var s = "hello world !"
s := replace(re"\w+", "masked")
echo s
{.experimental: "dotOperators".}
macro `.=`(s: string, call: untyped): untyped =
discard