英語の方は、ほとんどわかりません。The Seasoned SchemerやThe Little Schemer, 4th Editionは雰囲気と勢いで読みました。
The Seasoned Schemerに出てくる try のことを思い出しました。
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
;; try | |
(define-syntax try | |
(syntax-rules () | |
((_ var a . b) | |
(let/cc success | |
(let/cc var | |
(success a)) . b)))) | |
(define (accept-odd-only ls throw) | |
(let ((ret (every odd? ls))) | |
(if ret | |
ls | |
(throw ret)))) | |
(use srfi-1) | |
(try throw | |
(accept-odd-only '(1 2 3 4 5) throw) | |
(print "oops") | |
(print "error!")) | |
;; oops | |
;; error! | |
;; #<undef> | |
(try throw | |
(accept-odd-only '(1 3 5 7 9) throw) | |
(print "oops") | |
(print "error!")) | |
;; (1 3 5 7 9) | |
0 件のコメント:
コメントを投稿