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

后端 未结 6 2078
悲&欢浪女
悲&欢浪女 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:47

    (define (sublist list start number)
      (cond ((> start 0) (sublist (cdr list) (- start 1) number))
            ((> number 0) (cons (car list)
                          (sublist (cdr list) 0 (- number 1))))
            (else '())))
    

提交回复
热议问题