gpt4 book ai didi

common-lisp - Lisp 列表包含程序

转载 作者:行者123 更新时间:2023-12-03 18:18:25 25 4
gpt4 key购买 nike

如何制作一个 Lisp 程序来检查一个字符、字符串或数字是否在列表中?
(list-contains '(1 a 2 d 2 5) 'a) => T(list-contains '(1 a 2 d 2 5) 'x) => NIL

最佳答案

您可以使用 (find x the-list)如果 x 在列表中,则返回 x,否则返回 NIL。

(find 'a '(1 a 2 d 2 5)) ; A
(find 'x '(1 a 2 d 2 5)) ; NIL

关于common-lisp - Lisp 列表包含程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3198864/

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