You can't define top-level bindings outside of the top-level, in Scheme. (And inside of a let
is definitely outside of the top-level---what you had, instead, was internal definitions, which are not exported to the top-level.) However, using define-values
, you can still do what you need to do:
(define-values (my-incf my-decf)
(let ((x 0))
(values (lambda (y)
(set! x (+ x y))
x)
(lambda (y)
(set! x (- x y))
x))))
However, you can still use internal definitions, to make your code more readable:
(define-values (my-incf my-decf)
(let ((x 0))
(define (my-incf y)
(set! x (+ x y))
x)
(define (my-decf y)
(set! x (- x y))
x)
(values my-incf my-decf)))
Best of both worlds. :-) In this case, the values
sends the internal my-incf
and my-decf
definitions to the outer define-values
, which is where the real top-level definition happens.