> Empty is not uninitialized--they are two completely different concepts.

Yes, indeed, except that the compiler processes them the same way, i.e. both 
are considered to have length 0.

In fact, there are no uninitialized objects in Nim. If you write `var s: 
seq[int]`, the memory area representing `s` is filled with a nil value, which 
is semantically equivalent to a sequence of length 0. So, one can say that all 
sequences are by default initialized to a sequence of length 0. It was not the 
case in previous versions where a nil sequence was considered to be different 
of a sequence of length 0.

Said another way, in current version of Nim `var s: seq[int]` and `var s = 
newSeq[int]` are semantically equivalent, but represented differently.

I think that, as when interfacing with C we frequently need to get the address 
of the raw data, it would be helpful if a predefined proc existed for this 
purpose. But, as there are no semantic difference between a sequence with no 
memory allocated and a sequence of length 0, I’m afraid that we will not avoid 
one test and even two. This procedure would be equivalent to:
    
    
    proc bufferAddr[T](s: seq[T]): pointer =
      if s.len == 0: nil else: unsafeAddr(s[0])
    
    
    Run

There are two tests: one to compute the length and one to test the length.

Reply via email to