0

I am wondering get a sublist in a list,like:

user=> (findsublst '(hello world (10 clock)))
(10 clock)

what function can I use or how to define the functioin findsublst. Thank you so much!

Xiufen Xu
  • 531
  • 1
  • 3
  • 19
  • Is there any criteria for the sublist? In your example `last` would do the trick. – Chris Murphy Feb 16 '16 at 17:54
  • The sublist can be anywhere in the list. Like, '(the (2 big) boat), ((1 this) is (2 very) nice)), ((3 oh) wow).@ChrisMurphy – Xiufen Xu Feb 16 '16 at 17:57
  • If you need to do a lot of slicing, a vector is probably a better data type for that because it supports [`subvec`](https://clojuredocs.org/clojure.core/subvec). Can you work with vectors here? – jmargolisvt Feb 16 '16 at 17:59
  • This is not a duplicate of the suggested question, as discussed in [this comment](http://stackoverflow.com/questions/35439643/how-to-get-a-sublist-in-a-list-in-clojure#comment58577774_35439965) – Sam Estep Feb 16 '16 at 20:29

1 Answers1

4

With very little to go on, the following will return all first level list/sequences contained by the primary:

(filter seq? '(1 2 3 (4 5 6)))
=> ((4 5 6))
Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
Frank C.
  • 7,758
  • 4
  • 35
  • 45
  • 3
    That is indeed what I about to post (except that I added `first`). I think the confusion here comes from the OP's use of the term "sublist", which means "a portion of a list" rather than a list nested in a list, which is what he actually meant. – z7sg Ѫ Feb 16 '16 at 18:09
  • @z7sgѪ Yes, I was going to add `first` but it was ambiguous if there would potentially be multiple nested lists. – Frank C. Feb 16 '16 at 18:12
  • Thank you all! I want to get all the sublists in the list. So I do not need to use `first` here. You guys help me to clear my confusion! – Xiufen Xu Feb 16 '16 at 18:39