如何刪除common-lisp列表中的重複列表? 我嘗試這樣做:刪除lisp列表中的重複列表
(remove-duplicates '((1 2 3) (1 2 3)))
但它的計算結果((1 2 3) (1 2 3))
,不((1 2 3))
。
謝謝。
如何刪除common-lisp列表中的重複列表? 我嘗試這樣做:刪除lisp列表中的重複列表
(remove-duplicates '((1 2 3) (1 2 3)))
但它的計算結果((1 2 3) (1 2 3))
,不((1 2 3))
。
謝謝。
使用關鍵字參數:test
指定定義兩個項目是否是相互重複的功能。大多數lisp函數(包括remove-duplicates
)使用eql
默認情況下測試是否相等。 eql
比equal
嚴格得多,這是你可能想要使用的。
(remove-duplicates '((1 2 3) (1 2 3)) :test #'equal)
該評估爲'((1 2 3))
。
有關eql
和equal
之間的區別的更多詳細信息,請參閱this post。
嘗試:
(remove-duplicates '((1 2 3) (1 2 3)) :test #'equal)
這不是「第二可選參數」; 'test'是一個關鍵字參數。關鍵字參數的順序無關緊要。例如,你可以做'(remove-duplicates list:test'equal:from-end t)'或'(remove-duplicates list:from-end t:test'equal)',結果是一樣的。 Common Lisp中的可選參數是基於_position_的,但關鍵字參數不是。 –
@JoshuaTaylor好點。編輯。 – ApproachingDarknessFish