gpt4 book ai didi

null - andmap 和 null?返回错误

转载 作者:行者123 更新时间:2023-12-02 22:10:29 25 4
gpt4 key购买 nike

我想确定列表是否仅包含nullnull? 似乎是显而易见的选择:

> (null? null)
#t

但是对其进行andmap并没有达到我的预期:

> (andmap null? '(null))
#f

我是否误解了null?andmap?我是 Racket 新手,但根据文档,这似乎根本不正确。

最佳答案

您的问题是 '(null) 不是包含 null 的列表(即空列表)。以下是一些可行的选项:

  • (andmap null? '(()))
  • (andmap null? `(,null))(andmap null? (quasiquote (unquote null)))
  • (andmap null?(list null))

发生情况的说明:标识符 null 绑定(bind)到表示空列表的值。当您执行 'null 时,这相当于 (quote null) ,意思是“给我一个代表标识符的符号,而不是它代表的内容”(就像自然语言中的引用一样) )。

您可以通过使用表示 null '() 的文字或使用 quasiquoteunquote“转义”回来避免这种情况 Racket 。

有关引用的更多信息,请参阅 Guide entry就在上面。

关于null - andmap 和 null?返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16725426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com