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
;; P20 (*) Remove the K'th element from a list. | |
;; Example: | |
;; * (remove-at '(a b c d) 2) | |
;; (A C D) | |
#lang racket | |
(provide remove-at) | |
(define (remove-at lst pos) | |
(let loop ((lst lst) (ini 1) (acc '())) | |
(let ((tail (cdr lst))) | |
(if (= pos ini) | |
(append (reverse acc) tail) | |
(loop tail (+ ini 1) (cons (car lst) acc)))))) |
0 件のコメント:
コメントを投稿