I want to create a new reference object from an immutable (non-reference) object. Something like this:
type Something = object
a: int
proc f(s: Something) =
var x: ref Something = deepCopy(s)
This doesn't compile, but I would like something that works like this if the argument s to the deepCopy call would be a ref object.I guess you want something like this?
type Something = object
a: int
proc f(s: Something) =
var x = new(Something)
x[] = s
echo repr x
f(Something(a: 42))
proc to_ref*[T](o: T): ref T =
result.new
result[] = o