unfold は基本的な再帰的リスト コンストラクタ
fold-right と unfold はある意味で逆操作
unfold-right は基本的な反復的リスト コンストラクタ
fold と unfold-right はある意味で逆操作
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; SRFI 1: リスト ライブラリ http://www.chino-js.com/tech/srfi/srfi-1/srfi-1.html#zip | |
(use srfi-1) | |
(unfold-right null? car cdr (fold cons '() '(1 2 3 4 5))) | |
;; (1 2 3 4 5) | |
(let ((seq (cut <> cons '() '(1 2 3 4 5))) | |
(rev (cut <> null? car cdr <>))) | |
(values (rev unfold-right (seq fold)) | |
(rev unfold (seq fold-right)))) | |
;; (1 2 3 4 5) | |
;; (1 2 3 4 5) | |
(let ((seq (cut <> cons '() '(1 2 3 4 5))) | |
(rev (cut <> null? car cdr <>))) | |
(equal? (rev unfold-right (seq fold)) | |
(rev unfold (seq fold-right)))) | |
;; #t | |