replace-all   scheme


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

Implementation

(define replace-all
  (lambda (lst alst)
    (if (pair? lst)
        (let loop ((lsta lst) (lstb '()))
          (if (null? lsta)
              (reverse lstb)
              (let* ((v (car lsta))
                     (lstb2 (cond ((assoc v alst)
                                   (cons (cdr (assoc v alst)) lstb))
                                  ((list? v)
                                   (cons (loop v '()) lstb))
                                  ((pair? v)
                                   (cons (cons (car (loop (list (car v)) '()))
                                               (car (loop (list (cdr v)) '())))
                                         lstb))
                                  (#t (cons v lstb)))))
                (loop (cdr lsta) lstb2))))
        lst)))


Back to Index

Similar Entries

  • regex:replace-all    scheme