Cond different in definitions and interactions of DrRacket

DrRacket version 7.8 (both CS and BC), Windows 10.

In definitions window:
(not running it, background expansion enabled) or
(back-ground expansion disabled and running it):
(cond (#t 'monkey) (is this ignored?)) --> exception is: unbound identifier in: is

In interactions-window followed by return key:
(cond (#t 'monkey) (is this ignored?)) --> monkey

Is this intentional behaviour?
If not I'll be happy to issue an issue.
It's not a hot issue, though, I think.

1 Like

This is intentional behavior.

In the interaction window, you can incrementally evaluate expressions. So in a state, you might evaluate an expression that has a forward reference, but that reference has no corresponding definition yet. Here is an example.

> (define (even? x)
    (cond [(zero? x) #t] [else (odd? (sub1 x))])) 

;; --> at this point, odd? is not yet defined

> (define (odd? x)
    (cond [(zero? x) #f] [else (even? (sub1 x))]))

;; --> at this point, odd? is defined

Racket REPL wants to support this, so it must tolerate the situation.

In a module, there is no incrementality. So in:

#lang racket
(define (even? x)
  (cond [(zero? x) #t] [else (odd? (sub1 x))]))

Racket can conclude immediately that odd? is unbound.

What you observed is a consequence of this difference in the REPL / module.

4 Likes

Thanks, I did not think of that, stupid me, for i have heard the story earlier.