:add   scheme


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

Implementation

;+
;
;; ADD
;; 
; increase a result atom/list, using a value atom/list 
; if lengths don't match, adjust them automatically by slicing/repeating elements
;
; examples
; (:add 4 2) ;; 6
; (:add '(4 5) 2) ;; 6
; (:add '(4) '(2)) ;; '(6)
; (:add 4 '(2 10 22)) ;; '(6 14 26) 
; (:add '(4 2) '(2)) ;; '(6)
; (:add '(4) '(2 4 6)) ;; '(6 8 10)
; (:add '(5 4) '(g3 c4 g4 e3)) ;; '(72 76 83 68)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define :add
  (lambda (val res)
    (cond ((and (list? val) (list? res)) 
            (helper:inner-add val res))
          ((and (atom? val)  (list? res))
            (helper:inner-add (make-list (length res) val) res))
          ((and (atom? val) (atom? res))
            (+ val (eval res)))
          ((and (list? val) (atom? res))
            (+ (car val) (eval res)))
          (else '()))))


Back to Index

Similar Entries