How do I take a slice of a list (A sublist) in scheme?

后端 未结 6 2057
悲&欢浪女
悲&欢浪女 2020-12-31 07:09

Given a list, how would I select a new list, containing a slice of the original list (Given offset and number of elements) ?

EDIT:

Good suggestions so far. I

6条回答
  •  一整个雨季
    2020-12-31 07:49

    You can try this function:

    subseq sequence start &optional end

    The start parameter is your offset. The end parameter can be easily turned into the number of elements to grab by simply adding start + number-of-elements.

    A small bonus is that subseq works on all sequences, this includes not only lists but also string and vectors.

    Edit: It seems that not all lisp implementations have subseq, though it will do the job just fine if you have it.

提交回复
热议问题