Why does this work in DrRacket but not in Racket from the console
-
28-09-2020 - |
Question
(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
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow