(top)  (memo)  (rss)
Common Lisp のループマクロによる AA 降れ線グラフ (Haskell 版 , Scheme 版 (2006/03/14 21:31:12 PST))
CL-USER> (plot "RCRFCRFFCCRFFRRCRRCCFRFRFF")
__
/ \/\/\
_/\_/\ _/ \
/ \__/\ /
\/
NIL
CL-USER>
バリバリ値を書きかえてみる.
(defun plot (data &aux (top 0) (bottom 0) (current 0))
(labels ((parse (cur pos char)
(setf current cur
top (max top current)
bottom (min bottom current))
(cons pos char))
(aa-plot (buf)
(loop for n from top downto bottom do
(loop for (i . char) in buf do
(write-char (if (= i n) char #\space)))
(terpri))))
(aa-plot
(loop for c across data collect
(case c
(#\R (parse (1+ current) current #\/))
(#\F (parse (1- current) (1- current) #\\))
(#\C (parse current current #\_)))))))
が,Scheme 版より長かったです.
posted: 2006/03/18 18:01 | permanent link to this entry | Tags: LISP