[racket] confusion about shadowing predefined functions in interactions window

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Tue Oct 23 12:39:49 EDT 2012

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
    '(define (range lo)
       (lambda (hi) (if (> lo hi) null (cons lo ((range (+ 1 lo)) hi)))))))

  (lambda (lo)
     (lambda (hi)
        (if (#%app > lo hi)
             (#%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.


Jens Axel Søgaard

Jens Axel Søgaard

Posted on the users mailing list.