cl:subst   scheme


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

Implementation

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DEPRECATED / missing dependencies
;; subst amd sublis have gone missing? 
;; https://extempore.michelepasin.org/def/subst.html
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (cl:subst 9 7 '(5 (5 6 7 (6 7))))    =>  (5 (5 6 9 (6 9)))  
(define (cl:subst new old tree)
  (if (pair? tree)
      (let ((left (subst  new old (car tree)))
            (right (subst  new old (cdr tree))))
        (if (and (eq? left (car tree))
                 (eq? right (cdr tree)))
            tree
            (cons left right)))
      (if (eqv? old tree)
          new
          tree)))


Back to Index