insert-at-index   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/runtime/scheme.xtm

Implementation

; insert into list at index
(define insert-at-index
   (lambda (k lst obj)
      (cond ((or (null? lst)
     (< k 0))
       lst)
      ((= k 0)
       (cons obj lst))
      ((> k (length lst))
       lst)
      (else (set-cdr! (cl:nthcdr (- k 1) lst)
          (cons obj (cl:nthcdr k lst)))
      lst))))


Back to Index