There are 3 cases, play, in first and secod seq copied as val, in third as ref, why?
block:
var inbox = @[1]
let copy = inbox # val
inbox.setlen 0
echo "variable: ", copy.len # => 1
type Session = ref object
inbox: seq[int]
block:
let session = Session(inbox: @[1])
let copy = session.inbox # val
session.inbox.setlen 0
echo "field: ", copy.len # => 1
block:
proc process(session: Session): void =
let copy = session.inbox # ref? why?
session.inbox.set_len 0
echo "field in proc: ", copy.len # => 0
Session(inbox: @[1]).process
Output
variable: 1
field: 1
field in proc: 0 # <= Why?
All fine here:
variable: 1
field: 1
field in proc: 1
salewski@hx90 /tmp $ nim -v
Nim Compiler Version 1.9.3 [Linux: amd64]
But you may try "var copy = session.inbox", I think there was an issue with let maybe 6 years ago.