I am starting to learn the Scheme programming Language with Racket. I have a function in which another function is called, however this inner-function is not defined until after the definition of the outer-function. If I define the inner-function in the global-environment in which also the outer function is defined, every thing is fine, however in a let-environment the inner function seems to be not bound yet, and I get an unbound identifier error. Here is my code:
This fails:
#lang racket
(define (outer x) (lambda (y) (later-func x y)))
(let ([later-func (lambda (x y) (+ x y))])
((outer 8) 9))
But this version gets lucky and returns 17:
#lang racket
(define (outer x) (lambda (y) (later-func x y)))
(define (later-func x y) (+ x y))
((outer 8) 9)
I would really appreciate if some one could explain to me the concept, and maybe some reading stuff for further reading about this (PLEASE NO AI-generated content or sites!!!)