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
;; P16 (**) Drop every N'th element from a list. | |
;; Example: | |
;; * (drop '(a b c d e f g h i k) 3) | |
;; (A B D E G H K) | |
(define (drop lst x) | |
(let loop ((lst lst) (i 1) (acc '())) | |
(let ((revacc (reverse acc))) | |
(if (null? lst) | |
revacc | |
(let ((tail (cdr lst))) | |
(cond ((< (length lst) x) | |
(append revacc tail)) | |
((= i x) | |
(loop tail 1 acc)) | |
(else | |
(loop tail (+ 1 i) (cons (car lst) acc))))))))) |
0 件のコメント:
コメントを投稿