On 21.09.2021 21:03, Maxime Devos wrote: > > (define (foo2 set?) > (define x) ; define an (undefined or unbound, not sure about terminology) > variable > (if set? > (let () > (set! x 2) ; change the value of x > (display "x=") > (display x) > (newline)) > 'never) > (display x) > (newline)) >
I didn't know (define x) without a value was possible in Guile. I guess it's just a shorthand for (define x *unspecified*), judging by your result. If I'm not mistaken, the only way in Scheme to get a "defined but not yet bound" kind of situation is to use 'letrec'. If you use the 'letrec*' variant, it guarantees a straight order of evaluation, so the following is supposed to definitely NOT work, due to y and z being defined-not-bound: (letrec* ((x (+ y z)) (y (random 10)) (z (random 10))) (display x) (newline)) However, in Guile, it seems to bind all the variables to #<unspecified> anyway, resulting in a "wrong type argument" error (since we end up passing #<unspecified> to '+') instead of saying that y and z are not yet bound. Long story short, there doesn't seem to be *any* way in Guile to have a lexical variable that's defined but not bound. -- Taylan