In the cava interpreter, it works. In Guile, this is not so, because this code
(define (fx) (define ax) (define ba) b)
expands to
(define (fx) (letrec ((ax) (ba)) b))
And you cannot access a until appointment. letrec will not work for non-functional definitions, for example:
(letrec ((x 5) (yx)) y)
You can use let* insted
(define (fx) (let* ((ax) (ba)) b))
In this code
(define (fx) (define ax) (define (b) a) (b))
In procedure b, you access the variable if it is already defined.
source share