Add insert-between function

This commit is contained in:
Nikolay Puzanov 2022-11-22 19:19:17 +03:00
parent d98761d3a8
commit 7f17725012

View File

@ -15,6 +15,7 @@
number->bits number->bits
string-c-radix->number string-c-radix->number
has-duplicates? find-duplicates has-duplicates? find-duplicates
insert-between
make-mux-selectors)) make-mux-selectors))
(else (else
@ -166,3 +167,20 @@
(bits-first-diff-msb abits obits))) (bits-first-diff-msb abits obits)))
others)))))) others))))))
addrs))) addrs)))
;;; Insert object between list items
;; (define (insert-between lst x)
;; (if (null? lst)
;; lst
;; (reverse
;; (cdr
;; (fold (lambda (item out)
;; (cons* x item out))
;; '() lst)))))
(define (insert-between lst x)
(if (or (null? lst)
(null? (cdr lst)))
lst
(cons* (car lst) x
(insert-between (cdr lst) x))))