【问题标题】:Lisp - append to a listLisp - 附加到列表
【发布时间】:2015-03-08 15:42:56
【问题描述】:

我是 lisp 的新手。我没有正确理解如何在列表上实现附加功能。我尝试了以下程序。

(defvar temp)
(setq temp '())
(append temp (logxor 1 0))

temp 在应该存储 1 时似乎只存储 NIL 值。

【问题讨论】:

    标签: lisp common-lisp


    【解决方案1】:

    append 返回新值,它不修改其参数。 你需要使用setq:

    (setq temp (append temp (list 1)))
    

    push(添加到列表的开头,而不是结尾!):

    (push 1 temp)
    

    【讨论】:

      猜你喜欢
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      • 2012-12-20
      • 2014-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多