; File: multiplylist.scm ; Title: Multiplies each element of a list by n (first level) ;> (multlist 3 '( 3 4 5 6)) -> (9 12 15 18) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (multlist n L) (cond ((null? L) ()) (else (cons (* n (car L)) (multlist n (cdr L)))) )) ;; Same thing with tail recursion. (define (multlist2 n L) ; n is the multiplier, L the list (letrec ((multtaux (lambda (L R) ; R is the result (cond ((null? L) R) (else (multtaux (cdr L) (cons (* n (car L)) R))) ; add to R and take it off L )))) (multtaux L ()) ; Start with R empty )) ;;;;;;;;;;;;same thing using map This is how you should do it! (define (multlist3 n L) ; n is the multiplier, L the list (map (lambda(x) (* x n)) L) )