error i am not able to correct
Posted: Thu Oct 10, 2013 6:57 am
Hello everyone, i am in my first year of computer programming and we are working with drracket, scheme for now.
One of the tasks was to create a program to could display a certain character an "n" amount of times.
as such :
>(display-n c 5)
ccccc
here is my code :
(define display-n
(lambda (c n)
(display c)
(if (> n 1)
(display-n c (- n 1)))))
and i got it to work with numbers, but when i do it with characters, i get the error : cannot refrence an identifier before its definition. I thought that when you used lambda, te parameters arent evaluated. So i dont understand why scheme rejects any non-number.
thanks for your help
One of the tasks was to create a program to could display a certain character an "n" amount of times.
as such :
>(display-n c 5)
ccccc
here is my code :
(define display-n
(lambda (c n)
(display c)
(if (> n 1)
(display-n c (- n 1)))))
and i got it to work with numbers, but when i do it with characters, i get the error : cannot refrence an identifier before its definition. I thought that when you used lambda, te parameters arent evaluated. So i dont understand why scheme rejects any non-number.
thanks for your help