Footnote #28 of SICP says the following:
Embedded definitions must come first in a procedure body. The management is not responsible for the consequences of running programs that intertwine definition and use.
What exactly does this mean? I understand:
- "definitions" to be referring to both procedure creations and value assignments.
- "a procedure body" to be as defined in section 1.1.4. It's the code that comes after the list of parameters in a procedure's definition.
- "Embedded definitions must come first in a procedure body" to mean 'any definitions that are made and used in a procedure's body must come before anything else'.
- "intertwine definition and use" to mean 'calling a procedure or assigned value before it has been defined;'
However, this understanding seems to contradict the answers to this question, which has answers that I can summarise as 'the error that your quote is referring to is about using definitions at the start of a procedure's body that rely on definitions that are also at the start of that body'. This has me triply confused:
- That interpretation clearly contradicts what I've said above, but seems to have strong evidence - compiler rules - behind it.
- SICP seems happy to put definition in a body with other definitions that use them. Just look at the
sqrt
procedure just above the footnote! - At a glance, it looks to me that the linked question's author's real error was treating
num-prod
like a value in their definition ofnum
rather than as a procedure. However, the author clearly got it working, so I'm probably wrong.
So what's really going on? Where is the misunderstanding?