views:

178

answers:

1
(define pick
    (lambda (num lat)
      (cond ((null? lat) (quote()))
            ((= (sub1 num) 0) (car lat))
            (else 
                  (pick (sub1 num) (cdr lat))))))
(define brees (quote (a b c d e touchdown g h i)))
(pick 6 brees)

The language in DrRacket is set to Advanced Student. It also works fine in the IronScheme console after defining sub1.

The error message is:

reference to undefined identifier: R

alt text alt text

+2  A: 

When I type this into the console I get

Welcome to Racket v5.0.
> (define pick
    (lambda (num lat)
     (cond ((null? lat) (quote()))
        ((= (sub1 num) 0) (car lat))
        (else
              (pick (sub1 num) (cdr lat))))))
> (define brees (quote (a b c d e touchdown g h i)))
> (pick 6 brees)
'touchdown

How are you running this in the console? If you are loading it, you may need a #lang Racket for the first line.

deinst
I don't know what I was doing wrong. It seems to work now. I was just running Racket on windows by running racket.exe and entering everything into the REPL. Weird. Thanks.
ecounysis