[racket] confusion about shadowing predefined functions in interactions window
2012/10/23 Dan Grossman <djg at cs.washington.edu>:
>
> Thanks, David. I would be interested in someone walking through how this
> behavior arises -- as well as the design issue regarding the "hopeless
> top-level": Is this the least-bad option available or an unexpected
> consequence?
>
> --Dan
The expansion in the repl is:
> (syntax->datum
(expand
'(define (range lo)
(lambda (hi) (if (> lo hi) null (cons lo ((range (+ 1 lo)) hi)))))))
'(define-values
(range)
(lambda (lo)
(lambda (hi)
(if (#%app > lo hi)
null
(#%app cons lo (#%app (#%app range (#%app + '1 lo)) hi))))))
The tricky thing here is that the meaning of a define-values form is
dependent on context:
In an internal-definition context (see Internal Definitions), a
define-values form
introduces local bindings.
At the top level, the top-level binding for each id is created
after evaluating expr,
if it does not exist already, and the top-level mapping of each id
(in the namespace linked with the compiled definition) is set to the binding
at the same time.
An the documentation on an internal-definition context says:
A define-values form: The lexical context of all syntax objects
for the body
sequence is immediately enriched with bindings for the define-values form.
http://docs.racket-lang.org/reference/define.html?q=define-values&q=repl#(form._((quote._~23~25kernel)._define-values))
--
Jens Axel Søgaard
--
--
Jens Axel Søgaard