代码之家  ›  专栏  ›  技术社区  ›  nakiya

从头到尾都不能像我期望的那样工作

  •  3
  • nakiya  · 技术社区  · 15 年前
    [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 回复  |  直到 15 年前
        1
  •  6
  •   Gareth Rees    15 年前

    position 按文件规定工作。这个 hyperspec says :

    返回的位置是满足测试的最左边(如果from end为true)或最右边(如果from end为false)元素序列中的索引;否则返回nil。返回的索引相对于整个序列的左端, 不考虑开始、结束或从结束的值 .

        2
  •  2
  •   tobyodavies    15 年前

    尝试 (position 3 '(1 2 3 4 3 2 1) :from-end t) 去看看 :from-end 关键字实际上是…

    你想要的似乎要简单得多- (- (length list) (position elem list))