gpt4 book ai didi

multidimensional-array - common lisp 如何在二维数组中设置元素?

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

我想我只是使用 setq (或 setf ,我不太确定区别),但我不明白如何引用 [i][j] -lisp 数组中的第 -th 个元素。

我的开始条件是这样的:

? (setq x (make-array '(3 3)))
#2A((0 0 0) (0 0 0) (0 0 0))

我想改变,比如说,第三个“行”的第二个项目给这个:
? ;;; What Lisp code goes here?!
#2A((0 0 0) (0 0 0) (0 "blue" 0))

以下,我本以为很接近,给出了一个错误:
(setq (nth 1 (nth 2 x)) "blue")

那么正确的语法是什么?

谢谢!

最佳答案

我认为正确的方法是使用 setfaref像这样:

(setf (aref x 2 1) "blue")

更多详情请见 reference .

关于multidimensional-array - common lisp 如何在二维数组中设置元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18062016/

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