[plt-scheme] An odd bug with define-values
>>>>> "Akiva" == Akiva Kleiman <kela_bit at netvision.net.il> writes:
Akiva> (define-values (x y)
Akiva> (let ([x '*]
Akiva> [y '*])
Akiva> (define-values (x y)
Akiva> (values 3 x))
Akiva> (values x y)))
Akiva> (display "x = ") (display x)
Akiva> (newline)
Akiva> (display "y = ") (display y)
Akiva> would return:
Akiva> x = 3
Akiva> y = #<undefined>
Akiva> although it *should* return
Akiva> x = 3
Akiva> y = *
Akiva> Oops.
Akiva> The problem, I believe is that define-values prepares a location for the new
Akiva> variable before evaluating. Thus, when trying to refer to an outer varaiable
Akiva> with the same name, you actually refer to the inner variable. Which is still
Akiva> #<undefined>, of course.
No. DEFINE-VALUES (like DEFINE) is recursive, as a click on "Check
Syntax" in DrScheme and moving the mouse cursor over the "x" in
(values 3 x) will show you.
--
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla