If we call "var a:int", a is set to be 0. Then, are there any way to set to be call some proc like "default" immediately after "var" call? It seems that there is default proc for type int, string, float but these proc is not called after var call.
I know that we can make another macro "var2" to realize this purpose. I also know that calling "var a:seq[int]", a is set to be an empty seq and not nil. How is this done?
How about this example?
type S = object
a:int
proc default(t:typedesc[S]):S = S(a:42)
var s:S
echo s # (a: 0) not (a: 42)
Nim does not support default initialization, everything is just set to zero-filled memory. If you want to default-init something then manually write default (T) on call. So it would be var a = default(int).
Seq is set to empty because nim sequences and strings have value semantics (they cannot be nil)
See https://github.com/nim-lang/RFCs/issues/252 and https://github.com/nim-lang/RFCs/issues/378#issuecomment-846554090 for an after-var-call.