[racket] confusion about shadowing predefined functions in interactions window

From: Dan Grossman (djg at cs.washington.edu)
Date: Mon Oct 22 22:05:00 EDT 2012

[DrRacket version 5.3, Language: racket]

A colleague stumped me and I confirmed the behavior...

* range is a provided procedure, but suppose we redefine it ourselves, in
curried form:
(define (range lo)
   (lambda (hi) (if (> lo hi) null (cons lo ((range (+ 1 lo)) hi)))))


(define ((range lo) hi)
  (if (> lo hi) null (cons lo ((range (+ 1 lo)) hi))))

If you do this in the definitions window with #lang racket, no problem.  If
you do it in the interactions window, then the recursive call will instead
be bound to the provided procedure, leading to an arity error.

Indeed, this has nothing to do with currying.  If I instead define a
non-curried function:

(define (range lo hi)
    (print "hi")
    (if (> lo hi) null (cons lo (range (+ 1 lo) hi))))

in the definitions window, then running (range 3 7) in the interactions
window will print "hi" 6 times.

But if I define this non-curried function in the interactions window, it
prints "hi" only once -- the recursive call again binding to the built-in

I apologize if this is a known "feature" or a known "bug" -- I do scan the
release notes briefly when new versions come out, but don't remember
anything about this.  Any pointers?  Thanks!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20121022/fae055b9/attachment.html>

Posted on the users mailing list.