2010/09/23

ドット対をリストに変換する

基本的には終端を空リストにしたリストを返します。一応 terminal-fun にて終端を指定できるようにしました。
コードは以下の通り。
(use srfi-1)
(define (dotted-list->list dl . terminal-fun)
(let-optionals* terminal-fun ((terminal-fun (lambda _ '())))
(unfold not-pair? car cdr dl terminal-fun)))
(dotted-list->list '(a b . c))
;; (a b)
(dotted-list->list '(a b . c) identity)
;; (a b . c)
(dotted-list->list '(a b . c) (lambda (term)
(list term)))
;; (a b c)


プログラミングGauche

0 件のコメント:

コメントを投稿