yaottiの日記

 | 

2008-09-23

Exercise 4.30

01:17

Ex 4.30のa.

流れのまとめ(一部).

(begin (proc (car items))
       (for-each (proc (cdr items))))
=>
(eval-sequence '((proc (car items)) (for-each (proc (cdr items)))) <env>)
=>
(eval (proc (car items)) <env>)
(eval (for-each ...) <env>)
=>(前者のみ追う)
(apply (actual-value proc) (car items) <env>)
=>
(apply (force-it (eval proc <env>)) (car items) <env>)
=>
(apply (force-it (lookup-variable-value proc <env>)) (car items) <env>)
=>
(apply (force-it (thunk (lambda (x) (newline) (display x)) <env>)) (car items) <env>)
=>

;; force-it手続き
(let ((result (actual-value
	       (lambda (x) (newline) (display x))
	       <env>)))
	   (set-car! obj 'evaluated-thunk)
	   (set-car! (cdr obj) result)
	   (set-cdr! (cdr obj) '())
	   result)
;; result: (evaluated-thunk (procedure (x) ((newline) (display x)) <env>))

;; 元に戻ると,
(apply (procedure (x) ((newline) (display x)) <env>) (car items) <env>)
=>
(eval-sequence ((newline) (display x)) (extend-environment (x) (thunk (car items))
							   <env>))

;; (extend-environment (x) (thunk (car items)) <env>)を<new-env>とおく.
=>
(eval (newline) <new-env>)
(eval (display x) <new-env>)
=>
;; 略
;; どちらもapplication?はtrue
;; そして次にlookup-variable-valueへ
=>
(apply-primitive-procedure newline '() <new-env>)
(apply-primitive-procedure display '(x) <new-env>)

Cyの杞憂しているポイントは, (proc (car items))が(正確にはprocが)thunkになるだけで評価されないのではないか, ということ.


eval-sequenceでevalを使うと困るのは, lookup-variable-valueで見つけたものがthunkな時.

しかしこの問題の場合は, 手続きnewline/displayはthunkでない(基本手続き)なので評価される.


これでいいのかな…

MoktarMoktar2013/08/07 04:59It's imrvaptiee that more people make this exact point.

IonescuIonescu2013/08/08 15:50I was looking evreewhyre and this popped up like nothing!

SunilSunil2013/08/11 04:56Wow, your post makes mine look felbee. More power to you! http://cywgxfxhea.com [url=http://vcwovwk.com]vcwovwk[/url] [link=http://edfftazk.com]edfftazk[/link]

NariskeNariske2013/08/12 10:12I was drawn by the <a href="http://ltxifmowkho.com">hotsney</a> of what you write

 |