【入門】Common Lisp その8【質問よろず】
■ このスレッドは過去ログ倉庫に格納されています
0836デフォルトの名無しさん
2012/02/06(月) 19:03:40.19reduceを使えば良いんじゃないかな。というわけで、こんなんできました。
ハードコーディングしてる部分は、実際のコードでは修正してー。
(labels ((has-prefix-p (prefix x)
(let ((p (search prefix x)))
(and p (zerop p))))
(foop (x)
(has-prefix-p "foo" x))
(testp (x)
(has-prefix-p "test" x)))
(reduce (lambda (x r)
(if r
(destructuring-bind (last . rest) r
(if (and (foop last) (testp x))
(cons (concatenate 'string x (subseq last (length "foo")))
rest)
(cons x r)))
(cons x r)))
*list*
:from-end t
:initial-value nil))
■ このスレッドは過去ログ倉庫に格納されています