- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
一个函数一个宏
;; I am sorry for the confusing function name.
;; As one answer suggests, cons-if-not-member is the better name.
(defun cons-if-member (element list)
(if (member element list)
list
(cons element list)))
(defmacro pushnew-no-bells (element list)
"pushnew without place support"
`(setq ,list (cons-if-member ,element ,list)))
(let ((xx (list 1 2)))
(pushnew-no-bells 0 xx)
xx)
我不知道下面哪个是正确的:
cons-if-member 是一个非破坏性函数,pushnew-no-bells 是一个破坏性宏。
两者都是非破坏性的。
cons-if-member 是非破坏性函数,形容词“破坏性”和“非破坏性”不适用于宏。
以上都不是
我也不知道 pushnew 是否被认为是破坏性的,但我想通过首先放弃 place 支持来简化事情。
最佳答案
pushnew
改变了它的位置形式(第二个参数)的值,所以它是破坏性的:它改变了“就地”的东西,而不是仅仅创建一个新对象(它可能与一个共享结构现有的)。您的 cons-if-member
(最好称为 cons-unless-member
或 cons-if-not-member
)不会修改任何“就位”的东西,所以它实际上是非破坏性的。
请注意,顺便说一句,由于符号宏的存在,您不能真正排除“一般位置”支持。观察:
(defclass foo ()
((x :initform nil)))
(let ((instance (make-instance 'foo)))
(with-slots (x) instance
(pushnew-no-bells 1 x))
(format t "~&Now: ~S~%" (slot-value instance 'x)))
关于lisp - 没有地方支持的推新。它被认为是破坏性的宏吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16789594/
我正试图让这个 map 功能成为一个更具破坏性的版本。这意味着 map 函数会修改原始数组而不是新数组。 function map (array, callback) { var result =
破坏性 Lisp 函数名称中的“N”缩写是什么词? 最佳答案 这是一个直接的答案from Linearity的 link : The N stands for non-consing, meaning
这是带有数据绑定(bind)元素的 html: div data-bind="foreach: clientRequests" id="test2">
我是一名优秀的程序员,十分优秀!