Reputation: 260
I have a list '(1 2 3 4)
.
I want to subtract each value in the list by a value (for example 1).
I want to return the new list '(0 1 2 3)
.
I'm using R5RS.
I've attempted to use map
but failed.
I would rather use map
over defining my own iterative or recursive algorithm.
Upvotes: 1
Views: 939
Reputation: 66459
If you want to (- x value)
with each element x
, map that:
(map (lambda (x) (- x value)) data)
or you could use a curried function:
(define (subtract y) (lambda (x) (- x y)))`
(map (subtract value) data)
Upvotes: 4