Nim: [regression?] correct comparisons for nil strings/seqs?

Created on 28 Jun 2018  路  9Comments  路  Source: nim-lang/Nim

given this test

proc test() =
  var a: string
  echo  a == nil
  a = ""
  echo a == nil
  var b: seq[int]
  echo b == nil
  b = @[]
  echo b == nil

test() 

Nim 0.18.0 produces:

false
true
false

After commit correct comparisons for nil strings/seqs it produces:

true
true
true

Is this really what you mean by correct comparisons for nil strings/seqs?

(issue #8136 is related to this)

Most helpful comment

@dom96 I am sorry for you. But it will be for the greater good. And I think your example will still be understandable and valuable even if nil won't exist anymore in the language.

All 9 comments

I think now nil seq/string is the same thing as empty seq/string and #8136 needs to be fixed accordingly with that change

in the changelog we have this:

  • nil for strings/seqs is finally gone. Instead the default value for
    these is "" / @[].

I don't understand how this could imply that both "" == nil and @[] == nil are now true, while isNil("") and isNil(@[]) remain false as before.

I've said it before. New strings/seqs are coming and nil and isNil will fail to compile. No confusion will be possible.

Excellent! Good luck with this abitious endeavor!

can this be closed then?

Not as long as isNil(str) compiles.

@dom96 I am sorry for you. But it will be for the greater good. And I think your example will still be understandable and valuable even if nil won't exist anymore in the language.

can this be closed then?

Not as long as isNil(str) compiles.

isNil(str) doesn't compile anymore. This can be closed.

Was this page helpful?
0 / 5 - 0 ratings