测试是否阵列在口齿不清名单内 [英] Test if array is inside a list in lisp
问题描述
我有两个项目。第一, A-子
,是含有数组作为它的第一个元素,然后一些字符串作为剩余单元的明细表。另外,映射
,是它包含了一些阵列的列表。通过观察,可以很容易地看到, A-子
是映射
,虽然我不能找到一个函数会发现它适合我。
I have two items. The first, a-child
, is a list which contains an array as its first element and then some strings as the remaining elements. The other, mapped
, is a list which contains a number of arrays. By inspection, it's easy to see that a-child
is in mapped
, though I can't find a function which will find it for me.
我下面穷人口齿不清的风格道歉 - 我开始前几天,所以我没有拿起所有的公约尚未
I apologize for the poor lisp style below - I started a few days ago, so I haven't picked up all the conventions yet.
(defparameter a-child (list (#2A((1 2 3) (7 4 5) (9 8 6))) "U" "R" "R"))
(defparameter mapped (list (#2A((1 2 3) (7 4 5) (9 8 6))) (#2A((1 2 3) (4 5 6) (7 8 9)))))
(find (car a-child) mapped) ;;returns NIL
(member (car a-child) mapped) ;;returns NIL
(position (car a-child) mapped) ;;returns NIL
(equalp (car a-child) (car mapped)) ;;returns T
什么功能,我可以使用来寻找阵列的列表内的数组?谢谢你。
What function can I use to look for arrays within a list of arrays?? Thank you.
推荐答案
您的序列函数标有返回NIL将返回 T
如果您通过:测试#'equalp
他们
The Answer
Your sequence functions marked "returns NIL" will return T
if you pass :test #'equalp
to them.
Common Lisp中的默认两个参数的测试是<一个HREF =http://www.lispworks.com/documentation/HyperSpec/Body/f_eql.htm相对=nofollow> EQL
。
The default Two-Argument Test in Common Lisp is eql
.
这是4之间最合理的选择由ANSI标准CL提供通用的比较函数(!):
It is the most reasonable choice between the 4(!) general purpose comparison functions provided for by the ANSI CL standard:
-
EQ
是太依赖于实现,并为一个可能想要在数字和字符不起作用
eq
is too implementation-dependent and does not work as one probably wants on numbers and characters
等于
和 equalp
遍历对象,从而需要很长时间的巨大的人,也许永远不会终止循环的。
equal
and equalp
traverse objects and thus take long time for huge ones and may never terminate for circular ones.
又见<一个href=\"http://stackoverflow.com/questions/547436/whats-the-difference-between-eq-eql-equal-and-equalp-in-common-lisp\">the EQ,EQL,平等,equalp Common Lisp中之间的区别。
这篇关于测试是否阵列在口齿不清名单内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!