Hi All,<br><br>I am very new to Scheme<br><br>What is wrong with the following code?<br><br>--------------------------------------------------------------------------------------------------------------------------------<br>
#lang scheme<br>(require rnrs/base-6)<br>(letrec ([my-sum (lambda (l)<br> (if (null? l) <br> 0<br> (+ (car l) (my-sum (cdr l)))))])<br> (my-sum '(1 2 3 4)))<br>(define my-sum<br>
(lambda (l)<br> (if (null? l) <br> 0<br> (+ (car l) (my-sum (cdr l))))))<br><br>OUTPUT<br>Welcome to DrScheme, version 4.2.1 [3m].<br>Language: Module; memory limit: 128 megabytes.<br>10<br>> (my-sum '(1 2 3))<br>
. . mcar: expects argument of type <mutable-pair>; given (1 2 3)<br>--------------------------------------------------------------------------------------------------------------------------------<br><br><br>If I comment (require rnrs/base-6) or the letrec block the code works as intended<br>
--------------------------------------------------------------------------------------------------------------------------------<br>#lang scheme<br>;(require rnrs/base-6)<br>(letrec ([my-sum (lambda (l)<br> (if (null? l) <br>
0<br> (+ (car l) (my-sum (cdr l)))))])<br> (my-sum '(1 2 3 4)))<br>(define my-sum<br> (lambda (l)<br> (if (null? l) <br> 0<br> (+ (car l) (my-sum (cdr l))))))<br><br>
OUTPUT<br>Welcome to DrScheme, version 4.2.1 [3m].<br>Language: Module; memory limit: 128 megabytes.<br>10<br>> (my-sum '(1 2 3))<br>6<br>--------------------------------------------------------------------------------------------------------------------------------<br>
#lang scheme<br>(require rnrs/base-6)<br>#|(letrec ([my-sum (lambda (l)<br> (if (null? l) <br> 0<br> (+ (car l) (my-sum (cdr l)))))])<br> (my-sum '(1 2 3 4)))|#<br>(define my-sum<br>
(lambda (l)<br> (if (null? l) <br> 0<br> (+ (car l) (my-sum (cdr l))))))<br><br>OUTPUT<br>Welcome to DrScheme, version 4.2.1 [3m].<br>Language: Module; memory limit: 128 megabytes.<br>> (my-sum '(1 2 3))<br>
6<br>--------------------------------------------------------------------------------------------------------------------------------<br><br>Am I missing something?<br><br>Cheers,<br>Ganesh Gunasegaran<br>