多値を返す手続きから受け取った多値の n 番目を返すマクロ。
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
;; nth-value | |
;; http://web.archive.org/web/20060616054033/home.comcast.net/~prunesquallor/macro.txt | |
(define-syntax nth-value | |
(syntax-rules () | |
((_ n values-body) | |
(call-with-values | |
(lambda () values-body) | |
(lambda vals | |
(list-ref vals n)))))) | |
(nth-value 0 (apply values '(a b c d e f g))) | |
; -> a | |
(nth-value 3 (apply values '(a b c d e f g))) | |
; -> d | |
(nth-value 10 (apply values '(a b c d e f g))) | |
; -> *** ERROR: argument out of range: 10 | |
0 件のコメント:
コメントを投稿