Loading [MathJax]/extensions/tex2jax.js

2010年7月15日木曜日

Remove the K'th element from a list

;; 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))))))
view raw p20.ss hosted with ❤ by GitHub

0 件のコメント:

コメントを投稿