简体   繁体   English

在普通的lisp中复制结构列表

[英]copying list of structs in common lisp

I have a list of structs, and I want to write a function that alters some slots in the structs without affecting the original list. 我有一个结构列表,我想编写一个函数来改变结构中的一些插槽而不影响原始列表。 I tried using copy-list, but its not deep enough; 我尝试使用copy-list,但它不够深入; the slot values are also altered in the original list. 插槽值也在原始列表中更改。 My question is, is there a built-in function that does what I want?, or should I write my own one?. 我的问题是,是否有内置函数可以完成我想要的操作?或者我应该编写自己的函数? Thank you. 谢谢。

EDIT: 编辑:

I went on and wrote my own function, is there a built-in one that would do this though? 我接着编写了自己的函数,是否有一个可以执行此操作的内置函数?

(defun deep-copy (li)
    (if (null li)
        nil
        (cons (copy-structure (car li)) (deep-copy (rest li)))))

There is little value to have that function pre-defined. 预先定义该功能几乎没有价值。

Your code is just: 你的代码只是:

(mapcar #'copy-structure some-list)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM