Test if array is inside a list in lisp

萝らか妹 提交于 2019-11-26 04:56:08

问题


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.


回答1:


The Answer

Your sequence functions marked "returns NIL" will return T if you pass :test #'equalp to them.

The Reason

The default Two-Argument Test in Common Lisp is eql.

It is the most reasonable choice between the 4(!) general purpose comparison functions provided for by the ANSI CL standard:

  • eq is too implementation-dependent and does not work as one probably wants on numbers and characters

  • equal and equalp traverse objects and thus take long time for huge ones and may never terminate for circular ones.

See also the difference between eq, eql, equal, and equalp in Common Lisp.



来源:https://stackoverflow.com/questions/19287777/test-if-array-is-inside-a-list-in-lisp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!