2
votes

the following expression failed on DrRacket but successfuly evaluated on other Scheme interpreter:

(define (f x) (g x))

This special form defines a function f(x) that when invoked - returns the invocation of g(x). DrRacket complains that :

g: unbound identifier in: g

however, g must not be defined in that stage, since i just define f but not invoke (f) (i can bound g later but before calling (f) which is perfectly fine in other interpreters )

2
Yes, that's a behavior specific to Racket, it's more strict about checking for undefined procedures at compile time - which is a Good Thing™. AFAIK you can't turn it off. What would be the question?Óscar López
Also notice that you can define g after you've defined f in the code, the important part is that it must be defined somewhere before trying to execute the code.Óscar López

2 Answers

3
votes

If you want to runt R5RS code in DrRacket, you need to choose the R5RS first. In the menu "Language" choose the menu item "Choose Language...". Then under other languages choose "R5RS". Finally make sure "Disallow redefinition of initial bindings" is unselected.

Now you will get the same result as in the other implementations.

enter image description here

1
votes

When you press RUN it wraps the definitions as a module and compiles it. It does more flow analysis than interpreted code and it knows g will never exist since the whole file has been parsed. As long as you define g Racket will be ok, but you haven't defined it before not after and that is the problem.

As an alternative you can enter all the code in the interactive window. eg. enter image description here