If the special form (define) associates a name with a value, i.e (define x 2), then how does (define (sum-square a b) (define square (lambda (x) (* x x))) (+ (square a) (square b))) this works, since there are (define ...) and (+ ......).
I am not sure whether I got your question, but you shouldn't be confused by nested definitions. This is functionally equivalent to: (define square (lambda (x) (* x x))) (define (sum-square a b) (+ (square a) (square b))) as you can try out in any Scheme interpreter. The only difference is square is now available to be used in other top-level definitions. Since square is something generally useful, you may prefer this second version in this case. In other cases you just want to factor out some code of a definition to make it easier to read, even if this code is only used once thus you define that function locally as in your first example.
"define" doesn't only associate a name with a value. It can basically associate any symbol with any symbol, as long as the first symbol does not already represent something (e.g. the symbol "2". You cannot define "2" to be something else than "2"). It can associate it with a value, or an operator, or another name, or a list, or whatever. So there is no problem in defining something as an operation (in this case, (+...). This is the the principle of embedding. You can nest anything inside anything, be it a numerical value, and operation, a procedure, or the thing itself. Think about it like that: every piece of data is a process which is composed of the most fundamental logical objects: "0" and "1". Therefore, there is no essential difference between values, operations, processes and procedures.
Join our real-time social learning platform and learn together with your friends!