[Cs254f11] Simple mapping problem

Wm. Josiah Erikson wjerikson at hampshire.edu
Thu Nov 17 13:08:15 EST 2011


Just peel the parentheses off from the inside, right? First you want to 
map first down m and return a collection of the first values in m. Then 
you want to map inc down that resulting collection and return a 
collection that is the result of incrementing each of those values. You 
do that like this:

(map inc (map first m))

+ won't work because it expects two or more operands, but you could do:

(map #(+ 1 %) (map first m))

, which says "map a function, which I will define right here to be a 
function that adds 1 to its first argument (the % is the first argument, 
%2 would be the second, etc), down the collection that results from 
taking the first item of each item in m"

     -Josiah


On 11/17/11 12:05 PM, Jesse French wrote:
> (def m
> [[85 1]
>   [92 5/16]
>   [66 15/16]
>   [80 1/8]
>   [50 1/8]
>   [85 1/4]
>   [66 13/16]
>   [37 1/16]
>   [103 1/8]
>   [34 1/8]
>   [113 7/16]]

-- 
Wm. Josiah Erikson
Network Engineer
Hampshire College
Amherst, MA 01002
(413) 559-6091



More information about the Cs254f11 mailing list