sicp-ex-4.27



<< Previous exercise (4.26) | Index | Next exercise (4.28) >>


canardivore

  
  
  
 (define w (id (id 10))) 
  
 ;;; L-Eval input: 
 count 
 ;;; L-Eval value: 
 0 
 Defining w doesn't evaluate it. 
 ;;; L-Eval input: 
 w 
 ;;; L-Eval value: 
 10 
 now that w is in the prompt, w is forced to evaluate, evaluating both ids. so now w = 10, count = 2. 
 ;;; L-Eval input: 
 count 
 ;;;; L-Eval value: 
 2 

I got different result, which is very interesting

  
 ;;; L-Eval input: 
 (define count 0) 
 ;;; L-Eval value: 
 ok 
 ;;; L-Eval input: 
 (define (id x) (set! count (+ count 1)) x) 
 ;;; L-Eval value: 
 ok 
 ;;; L-Eval input: 
 (define w (id (id 10))) 
 ;;; L-Eval value: 
 ok 
 ;;; L-Eval input: 
 count 
 ;;; L-Eval value: 
 1 
 **It's not zero here** 
 ;;; L-Eval input: 
 w 
 ;;; L-Eval value: 
 10 
 ;;; L-Eval input: 
 count 
 ;;; L-Eval value: 
 2 
 **changed after "w"** 
 ;;; L-Eval input: 
 w 
 ;;; L-Eval value: 
 10 
 ;;; L-Eval input: 
 count 
 ;;; L-Eval value: 
 3 
 **changed after "w", again!** 
 ;;; L-Eval input: 
 w 
 ;;; L-Eval value: 
 10 
 ;;; L-Eval input: 
 count 
 ;;; L-Eval value: 
 4 
 **changed after "w", one more time!** 
 ;;; L-Eval input: