[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
怎么办?
答案 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))