<< Previous exercise (4.27) | Index | Next exercise (4.29) >>
a simpler example
(define (proc operate) operate) ; error: Unknown procedure type -- APPLY (thunk + (...)) ((proc +) 1 2)
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?
poly
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.