0

I'm writing an ADT in r5rs and I'm using DrRacket. I put #lang r5rs at the top of my file and chose Determine Language from Source from DrRacket, but it tells me my ADT is undefined. I'm using DrRacket version 6.0. It's the first time I've had this and can't understand what I'm doing wrong.

My ADT

#lang r5rs
(#%require "queue.rkt") ;A required file
(#%provide (all-defined))

(define (my-ADT)
    (let ((val1 '())
          (val2 '()))

    (define (foo) ...)
    (define (bar) ...)

    (define (dispatch msg)
        (case msg
            ((foo) foo)
            ((bar) bar)
            (else "Unknown message")))

    dispatch))

When I try to create an instance of my-ADT I get the following output: my-ADT: undefined; cannot reference an identifier before its definition

When I remove #lang r5rs from the top and choose R5RS as language in DrRacket, it seems to work. But then my queue.rkt file still has #lang r5rs at the top and Determine Language from Source. When I remote #lang r5rs and choose R5RS as language in that file also, I get the following in the my-ADT file:

default-load-handler: expected a `module' declaration
found: something else
in: #<path:/Users/path/path/path/queue.rkt>
JNevens
  • 11,202
  • 9
  • 46
  • 72

1 Answers1

-1

The error

my-ADT: undefined; cannot reference an identifier before its definition

normally indicates that the function my-ADT was used before it was defined. That is, one must place all definitions on top of the file and place the expressions below.

Your example above has no uses of my-ADT so if you get this error, the problem might be in "queue.rkt". Can you run "queue.rkt" without errors?

soegaard
  • 30,661
  • 4
  • 57
  • 106