Take the following function definition as my example:
(define (foo)
(bar)
(define (bar)
(display "bar")))
This would produce an error: ;Premature reference to reserved name: bar. On the contrary, the following two definitions are legitimate. Note that I'm using premature reference in both of them.
(define (foo)
(bar))
(define (bar)
(display "bar"))
(define (foo)
(define (bar)
(display "bar"))
(bar))
My question is: why can't I prematurely reference a currently undefined function when using block structure? And why is bar a "reserved name"?
defines may occur only at the beginning of the body of adefine,lambda,let,let*,letrecetc (according to r5rs). - manualcrankdefineto appear anywhere in the body of a containingdefine? - nalzokbaris invoked before its definition. - manualcrank(define (foo) (bar) (define (bar) (display "bar")) (bar)). Notice, though, the extra(bar)after its definition; Racket insists on at least one expression after a sequence of internal definitions. Chez Scheme, OTOH, rejects both this and your originalfooat compile time. - manualcrank