I noticed that some standard library procs have a var parameter when, as far as i can tell, it would suffice to return a new value. For example:
# from system
proc new[T](a: var ref T)
# from sets
proc init[A](s: var HashSet[A]; initialSize = defaultInitialSize)
# from threads
proc createThread[TArg](t: var Thread[TArg]; tp: proc (arg: TArg); param: TArg)
Why don't these look like this instead?
proc new[T](): ref T
proc init[A](initialSize = defaultInitialSize): HashSet[A]
proc createThread[TArg](tp: proc (arg: TArg); param: TArg): Thread[TArg]
Then, using new as an example, one could write this:
var a = new[int]()
# instead of
var a: ref int
new(a)
Other procs, like initTable (from tables) already follow this pattern, while newSeq has both options, so there is no real consistency regarding this in the standard library.For new, you can write like this let foo = new(Foo) at least since 1.0.0
As for hashset and thread, they are not ref/ptr, but value in Nim semantic. And you can call initHashSet() instead of s.init().