sicp-ex-4.28



<< Previous exercise (4.27) | Index | Next exercise (4.29) >>


meteorgan

  
  
 for example: 
 (define (g x) (+ x 1)) 
 (define (f g x) (g x)) 
  
 when call (f g 10), if don't use actual-value which will call force-it, g will be passed as parameter which will be delayed, then g is a thunk, can't be used as function to call 10. 

Let me make meteorgan's answer more specific. 'g' will be passed as a parameter which will be delayed literally. It means 'g' is a thunk and (g 10) will be considered as application in the 'eval'. In the procedure apply, the 'g' will be seen as a procedure, with a tag 'thunk', which is not a primitive procedure and compound procedure. So the procedure apply will report an error.



Sphinxsky

a simpler example

  
  
 (define (proc operate) operate) 
 ; error: Unknown procedure type -- APPLY (thunk + (...)) 
 ((proc +) 1 2) 

Could anyone provide more detailed explanation for this?


I understand neither the context nor the intention of this code, but except for the comment it seems perfectly fine:

 $ racket 
 Welcome to Racket v7.9 [bc]. 
 > (define (proc x) x) 
 > ((proc +) 1 2) 
 3 
 >  

The comment is more sloppy than wrong; apply works as expected

 > (apply (proc +) (list 1 2)) 
 3 
 >  

although why apply is of interest is unclear. The unknown procedure type error is mysterious both in its meaning and to what it is referring. Thunk is being misued; generally construed, a thunk is a parameterless procedure, so it is unnecessary, although possible, to call one via apply

 > (define (one) 1) 
 > (apply one '()) 
 1 
 > (one) 
 1 
 >  

What in particular do you feel requires a more detailed explanation?