gpt4 book ai didi

lisp - 如何在 common-lisp 中每次从列表中获取两个元素?

转载 作者:太空宇宙 更新时间:2023-11-03 18:41:56 26 4
gpt4 key购买 nike

对于 ((1 2) (3 4) (5 6)),您可以使用 loop for (a b) in '((1 2) (3 4) (5 6)) 每次得到a = 1, b = 2。

但对于 '(1 2 3 4),我尝试通过 #'cddr for a = (car x) for loop for x on '(1 2 3 4) b = (cadr x) 得到 a = 1, b = 2。

有没有更好的方法来做这样的事情?

最佳答案

尝试for ... on:

(loop for (a b) on '(1 2 3 4) by #'cddr collect (cons a b))

关于lisp - 如何在 common-lisp 中每次从列表中获取两个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9310913/

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