我如何才能将列表的一部分放在特殊元素的前面? [英] How can I get the part of a list in front of a special element?

查看:79
本文介绍了我如何才能将列表的一部分放在特殊元素的前面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有了成员,我得到了被搜索的元素和列表的其余部分.但是在搜索到的元素出现之前,我如何获得这些元素?

With the MEMBER I get the searched element and the rest of the LIST. But how did I get the elements befor the searched element is coming?

(CDR (MEMBER 'DURCH '(ZEIT MAL LAENGE DURCH MASSE MAL ZEIT))); with this I get (MASSE MAL ZEIT)
;But how did I get (ZEIT MAL LAENGE) 

推荐答案

有时这些函数易于编写且解决方案非常透明以至于无法确定标准函数的哪种组合可以满足您的需求:

Sometimes these functions are so easy to write and the solution is so transparent to read that there's no point in working out which combination of standard functions will do what you want:

(defun elts-before (l elt &key (test #'eql))
  (loop for e in l
        until (funcall test e elt)
        collect e))

这篇关于我如何才能将列表的一部分放在特殊元素的前面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆