从头到尾不起作用,就像我期望的那样

时间:2010-11-27 05:55:35

标签: lisp common-lisp

[18]> (position 3 '(1 2 3 4 5 6 7 8) :from-end nil)
2
[19]> (position 3 '(1 2 3 4 5 6 7 8) :from-end t)
2

怎么办?

2 个答案:

答案 0 :(得分:6)

position正在记录中工作。 hyperspec says

  

返回的位置是满足测试的最左边(如果从结尾为真)或最右边(如果从结尾为假)元素的序列中的索引;否则返回nil。返回的索引是相对于整个序列的左端,,无论start,end还是from-end 的值。

答案 1 :(得分:2)

尝试(position 3 '(1 2 3 4 3 2 1) :from-end t)查看:from-end关键字实际执行的操作...

您想要的更简单 - (- (length list) (position elem list))