- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
查看 docs for #'adjoin在 HyperSpec 中,我在示例部分看到以下内容:
(setq slist '()) => NIL
(setq slist (adjoin '(test-item 1) slist)) => ((TEST-ITEM 1))
(adjoin '(new-test-item 1) slist :key #'cadr) => ((TEST-ITEM 1))
我本来期望的是:
(adjoin '(new-test-item 1) slist :key #'cadr) => ((NEW-TEST-ITEM 1) (TEST-ITEM 1))
我的期望是由于 HyperSpec (17.2.1) 中的以下文本:
When an object O is being considered iteratively against each element Ei of a sequence S by an operator F listed in the next figure, it is sometimes useful to control the way in which the presence of O is tested in S is tested by F. This control is offered on the basis of a function designated with either a :test or :test-not argument.
并且,进一步:
The object O might not be compared directly to Ei. If a :key argument is provided, it is a designator for a function of one argument to be called with each Ei as an argument, and yielding an object Zi to be used for comparison. (If there is no :key argument, Zi is Ei.)
The function designated by the :key argument is never called on O itself. However, if the function operates on multiple sequences (e.g., as happens in set-difference), O will be the result of calling the :key function on an element of the other sequence.
所以我们有 slist(序列,S)作为 '((TEST-ITEM 1))
和 O 作为 '(new-test-item 1)
。为了检查 O 是否应该连接,将函数 #'cadr
应用于 S 的元素,第一个元素是 '(test-item 1)
。所以,该测试给出:
(cadr '(test-item 1)) => 1
现在,当 O, '(new-test-item 1)
被检查为将 #'cadr
应用于 S 的 E1 的结果时 #'eql
(:test
提供 none 时使用的相等函数),false
结果应该意味着 O 是邻接的。至少那是我的想法。我误会了什么?
最佳答案
这是 HyperSpec 和 Issue ADJOIN-SPECIFICATION 中的错误已经在 CLiki 上写过。相关部分是:
Problem Description:
CLHS specifies ADJOIN behavior in presence of a :KEY argument by reference to Section 17.2.1 Satisfying a Two-Argument Test. This is incorrect, since section 17.2.1 specifies that the key function is NOT called on the ITEM parameter, but ADJOIN does, as is specified in pushnew. Proposal (ADJOIN:CLARIFICATION):
Replace:
The test, test-not, and key affect how it is determined whether item is the same as an element of list. For details, see Section 17.2.1 (Satisfying a Two-Argument Test).
通过:
Whether or not item is already a member of the list is determined by comparisons using :test or :test-not. The first argument to the :test or :test-not function is the result returned by the :key function (if supplied), applied to the item; the second argument is an element of the list as returned by the :key function (if supplied). If :key is supplied, it is used to extract the part to be tested from both item and the list element.
理由:
阐明 ADJOIN 的规范。
目前的做法:
所有实现都按照在 pushnew 上指定的方式实现 ADJOIN,而不是在 adjoin 上指定。
关于lisp - #'adjoin in Common Lisp work as per HyperSpec when used with ` :key`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22359337/
我要输出:.selector.another-selector .selector__block{一些声明}但我想嵌套它: 我在最后使用 &,所以我可以将它嵌套在 __block 下,但是如何让它与
我正在尝试制定一个程序,将一个数字连接到一组从小到大排序的数字。在这个集合中,没有重复项,所以我尝试通过检查要连接的数字是否已经等于集合的 car 来递归解决这个问题,如果为真则返回集合返回,如果号码
我想写下面的例子: (adjoin-set 2 (adjoin-set 8 (adjoin-set 4 (adjoin-set 3 (adjoin-set 7 (adjoin-set 5 '())))
查看 docs for #'adjoin在 HyperSpec 中,我在示例部分看到以下内容: (setq slist '()) => NIL (setq slist (adjoin '(test-
我正在尝试使用 display:table-cell 创建两个相同高度的列,然后将第三个相同高度的叠加 div 放置在前两列的顶部以隐藏它们。两个相同高度的列工作。但我不知道如何使第三个 div 与前
我是一名优秀的程序员,十分优秀!