疑问:Nil 不是空列表?Scheme学习遇repl.it返回#f问题
Why does "Nil is not the empty list?" return #f in Scheme?
Hey there! Let's unpack this confusion step by step.
First, let's translate that natural language question into actual Scheme code—what you're essentially evaluating is something like:
(not (eq? nil '()))
When this returns #f, it means the negation is false—so the underlying statement (nil is the empty list) is actually true.
Here's why that's the case in most Scheme implementations (including the one on repl.it):
- In standard Scheme,
nilis a predefined symbol that's bound directly to the empty list(). Think of it as a nickname for()—they refer to the exact same value. - If you test their equality with
eq?(which checks if two values are the same object) orequal?(which checks structural equality), you'll get#tevery time:(eq? nil '()) ; Returns #t (equal? nil '()) ; Also returns #t - So when you wrap that in
notto ask "is nil NOT the empty list?", the result is#fbecause the core equality check is true.
A common point of confusion here comes from other Lisp dialects (like Common Lisp) where nil has slightly different behavior, but Scheme keeps it straightforward: nil and () are interchangeable as the empty list.
Hope this clears things up!
内容的提问来源于stack exchange,提问作者Eugene
相关产品推荐
相关产品推荐

