I'm learning Scheme for the first time, and for practice I'm trying to write a program that returns a list of a specified length with all values equal to 1. I'm using the MIT/GNU Edwin editor on Windows 10. Here's the code I typed:
(define (listlength n)
(if (= n 1)
(list 1)
(append (list 1) (listlength (- n 1)))))
(listlength 5)
I would hope for C-x C-e
to return (1 1 1 1 1)
, but instead I get an unbound variable error:
;Unbound variable: listlength
;To continue, call RESTART with an option number:
; (RESTART 3) => Specify a value to use instead of listlength.
; (RESTART 2) => Define listlength to a given value.
; (RESTART 1) => Return to read-eval-print level 1.
;Start debugger? (y or n):
The only reason I can think of is that it doesn't like me calling listlength in the definition of listlength, but that's supposed to be part of what makes Scheme Scheme, so??? i'm at a loss?? Thanks for any help you can give me!
C-x C-e
before to evaluate the function definition? Or did you pressC-x C-e
only at the end of the(listlength 5)
form? See the manual. – Renzo