using recursion to create a new list
- From: "trivas7" <trivas7@xxxxxxxxx>
- Date: 23 Jan 2006 18:53:30 -0800
I've written a function that takes a number and returns a list of all
the integer multiples of that number from 1 to 10, in as simple a way
as I can think of. Given the number 3, my function returns the list:
(define (multiples-list num)
(append (list num)
(map (lambda (x) (* num x))
'(2 3 4 5 6 7 8 9 10))))
==> (3 6 9 12 15 18 21 24 27 30)
How do I go about thinking recursively to do this by making a new list?
I.e., using a mapping function ala
;; Return a list of the square roots of the numbers in a list
(define (square-roots a-list)
(if (null? a-list)
'()
(cons (sqrt (car a-list))
(square-roots (cdr a-list)))))
.
- Follow-Ups:
- Prev by Date: Re: Data aggregate
- Next by Date: Re: Equality, Assignment and The Emperor's New Clothes
- Previous by thread: Data aggregate
- Next by thread: Re: using recursion to create a new list
- Index(es):
Relevant Pages
|
Loading