Skip to content

Commit

Permalink
q4.5 -- extended cond =>
Browse files Browse the repository at this point in the history
  • Loading branch information
thash committed Oct 14, 2012
1 parent fab9a80 commit 713c619
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion q4.4.scm
Expand Up @@ -44,7 +44,7 @@
;;... ;;...
) )


;; コレの親玉であるexpand-clauses は何やってるのか. clause = "節". ;; コレの親玉であるexpand-clauses はcondの評価にのみ使われている. clause = "節".
;; ここでは生true/falseではなくevalされる表現として'true/'falseを返してる. ;; ここでは生true/falseではなくevalされる表現として'true/'falseを返してる.
(define (expand-and-clauses clauses) (define (expand-and-clauses clauses)
(if (null? clauses) (if (null? clauses)
Expand Down
28 changes: 28 additions & 0 deletions q4.5.scm
@@ -0,0 +1,28 @@
;; 裏condを実装せよ.
;; (<test> => <recipient>)
;; <test>が真の値に評価されると<recipient>>が評価される.

;; 例
(cond ((assoc 'b '((a 1) (b 2))) => cadr)
(else #f))

;; expand-clausesはcondの評価にのみ使われている.
;; clausesには, (cond のみが除かれた条件と式のペアリストがずらずらと渡ってくる.
;; expand-clauses内, make-ifに渡す引数を変えるため, cond-actionsを調整/拡張する.

;; 元
;(define (cond-actions clause) (cdr clause))

;; => 形式かどうかを判定する
(define (extended-cond? clause)
(if (cond-else-clause? clause)
#f
(eq? (cadr clause) '=>)))

;; => 形式の時は順序をいじって返せばよい
(define (cond-actions clause)
(if (extended-cond? clause)
(list (caddr clause) (car clause))
(cdr clause)))


0 comments on commit 713c619

Please sign in to comment.