#:g1: lisp 1.5でL-99 (P08 連続して現われる要素を圧縮)

Posted 2008-05-24 09:02:00 GMT

-(http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html)
なんとなくポインタ操作系で。

compress((a a a a b c c a a d e e e e))
; FUNCTION   EVALQUOTE   HAS BEEN ENTERED, ARGUMENTS..
;COMPRESS
;
; ((A A A A B C C A A D E E E E))
;
;
; END OF EVALQUOTE, VALUE IS ..
; (A B C A D E)

DEFINE(( (COMPRESS (LAMBDA (LST) (PROG (L RES TEM) (SETQ L LST) (SETQ RES (LIST (GENSYM))) (SETQ TEM RES) L (COND ((NULL L) (RETURN (CDR RES)))) (COND ((NOT (EQ (CAR L) (CAR TEM))) (PROG () (RPLACD TEM (LIST (CAR L))) (SETQ TEM (CDR TEM))))) (SETQ L (CDR L)) (GO L)))) ))


comments powered by Disqus