This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; P12 (**) Decode a run-length encoded list. | |
;; Given a run-length code list generated as specified in problem P11. Construct its uncompressed version. | |
(define (decode lst) | |
(let loop ((lst lst) (acc '())) | |
(if (null? lst) | |
(reverse acc) | |
(let ((head (car lst))) | |
(loop (cdr lst) (append | |
(if (pair? head) | |
(decode-aux head) | |
`(,head)) acc)))))) | |
(define (decode-aux lst) | |
(let ((n (car lst)) (symb (cadr lst))) | |
(let loop ((n n) (acc '())) | |
(if (zero? n) | |
acc | |
(loop (- n 1) (cons symb acc)))))) |
0 件のコメント:
コメントを投稿