[plt-scheme] Side effect requiring rnrs/base-6?
Hi All,
I am very new to Scheme
What is wrong with the following code?
--------------------------------------------------------------------------------------------------------------------------------
#lang scheme
(require rnrs/base-6)
(letrec ([my-sum (lambda (l)
(if (null? l)
0
(+ (car l) (my-sum (cdr l)))))])
(my-sum '(1 2 3 4)))
(define my-sum
(lambda (l)
(if (null? l)
0
(+ (car l) (my-sum (cdr l))))))
OUTPUT
Welcome to DrScheme, version 4.2.1 [3m].
Language: Module; memory limit: 128 megabytes.
10
> (my-sum '(1 2 3))
. . mcar: expects argument of type <mutable-pair>; given (1 2 3)
--------------------------------------------------------------------------------------------------------------------------------
If I comment (require rnrs/base-6) or the letrec block the code works as
intended
--------------------------------------------------------------------------------------------------------------------------------
#lang scheme
;(require rnrs/base-6)
(letrec ([my-sum (lambda (l)
(if (null? l)
0
(+ (car l) (my-sum (cdr l)))))])
(my-sum '(1 2 3 4)))
(define my-sum
(lambda (l)
(if (null? l)
0
(+ (car l) (my-sum (cdr l))))))
OUTPUT
Welcome to DrScheme, version 4.2.1 [3m].
Language: Module; memory limit: 128 megabytes.
10
> (my-sum '(1 2 3))
6
--------------------------------------------------------------------------------------------------------------------------------
#lang scheme
(require rnrs/base-6)
#|(letrec ([my-sum (lambda (l)
(if (null? l)
0
(+ (car l) (my-sum (cdr l)))))])
(my-sum '(1 2 3 4)))|#
(define my-sum
(lambda (l)
(if (null? l)
0
(+ (car l) (my-sum (cdr l))))))
OUTPUT
Welcome to DrScheme, version 4.2.1 [3m].
Language: Module; memory limit: 128 megabytes.
> (my-sum '(1 2 3))
6
--------------------------------------------------------------------------------------------------------------------------------
Am I missing something?
Cheers,
Ganesh Gunasegaran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090916/50ac058f/attachment.html>