Closed tmalsburg closed 9 years ago
I disagree, specifying a wrong type is a programming bug and should always result in an error. Cf. built-in functions such as zerop
.
Serious question: why is nil the "wrong" type? Nil is often used to indicate the absence of a value of any type.
Yes, but it's not a string ((stringp nil)
is nil
). Currently the contract for f-directory?
is simple and strict, the argument must be a string. Adding nil
as allowed argument would weaken the contract, require additional special-casing, and introduce unnecessary ambiguity (what is the meaning of the absence of a path name?).
nil
is otherwise known as Hoare's "billion-dollar mistake" (http://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare). If we can avoid weakening the contract for existing functions, we should.
To decide these things I usually look at other languages, for example Ruby:
$ File.exists?(nil)
TypeError: no implicit conversion of nil into String
Ok, convinced.
Wouldn't it be more convenient it if would just return
nil
?