Hatena::Groupcadr

わだばLisperになる このページをアンテナに追加 RSSフィード

2004 | 12 |
2005 | 01 | 02 | 07 | 10 | 11 |
2006 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2007 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2008 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2009 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2010 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2011 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 11 |

2007-02-10

L-99 (20)

| 17:16 | L-99 (20) - わだばLisperになる を含むブックマーク はてなブックマーク - L-99 (20) - わだばLisperになる

L-99 20問目に挑戦 - L-99:Ninety-Nine Lisp Problems

P20

解答
;;; Common Lisp
(defun remove-at (list n)
  (do ((l list (cdr l))
       (c 1 (1+ c))
       (retlist '() (if (= c n)
			retlist
			`(,@retlist ,(car l)))))
      ((endp l) retlist)))

;;PROG版
(DEFUN REMOVE-AT (LIST N)
  (PROG (L C RETLIST)
     (SETQ L LIST)
     (SETQ C 1)
     (SETQ RETLIST '())
L    (COND ((NULL L) (GO XIT)))
     (OR (= C N)
	 (SETQ RETLIST (CONS (CAR L) RETLIST)))
     (SETQ C (1+ C))
     (SETQ L (CDR L))
     (GO L)
XIT  (RETURN (NREVERSE RETLIST))))

;; Scheme
(define (remove-at ls n)
  (let remove-at1 ((l ls) (c 1) (retlist '()))
    (cond ((null? l) 
	   retlist)
	  ((= c n) 
	   (remove-at1 (cdr l) 
		       (+ c 1) 
		       retlist))
	  (else 
	   (remove-at1 (cdr l) 
		       (+ c 1) 
		       `(,@retlist ,(car l)))))))