takel   scheme


Defined in:  https://github.com/lambdamusic/extempore-extensions/blob/main/init/init_lisp.xtm

Implementation

;
; takelist - take one or more elements from a list and return a list
;
; (takel 1 '(10 20 30 40)) ; +> (10) 
; (takel '(1 4) '(10 20 30 40)) ; +> (10 40) 
; (takel '(1 5) '(10 20 30 40)) ; +> (10 #f) 
(define takel (lambda (indices lst)
    (let ((els (if (list? indices) 
                    indices
                    (list indices))))   
        (map (lambda (x)
                (if (< (length lst) x)
                    (begin (log-info "List too short for take") #f)
                    (list-ref lst (if (> x 0) (- x 1) 0))))  ;; 0 == 1 / trick to make it easier to work with sin functions
            els))))


Back to Index