替换Common Lisp中列表中的项目? [英] Replace an item in a list in Common Lisp?

查看:83
本文介绍了替换Common Lisp中列表中的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个事物列表(我称它为L),一个索引(N)和一个新事物(NEW).如果我想用NEW替换N中L处的东西,什么是最好的方法?我是否应该使子列表最多达到N,从N到列表的末尾,然后从第一部分NEW到最后一部分使用list将新列表粘合在一起?还是有更好的方法来做到这一点?

I have a list of things (I'll call it L), an index(N) and a new thing(NEW). If I want to replace the thing in L at N with NEW, what is the best way to do this? Should I get the sublist up to N and from N to the end of the list and then glue together a new list from the first part, NEW, and the last part using list? Or is there a better way to do this?

推荐答案

(setf (nth N L) NEW)

应该可以解决问题.

这篇关于替换Common Lisp中列表中的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆