Why does this work in DrRacket but not in Racket from the console
(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 开发者_StackOverflow中文版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
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.
精彩评论