Also, you could do it with only one map:<br><br>(map #(+ 5 (first %)) m)<br><br>This just maps a function down m that adds 5 to the first thing in the inner vector.<br><br>-Tom<br><br><div class="gmail_quote">On Thu, Nov 17, 2011 at 1:05 PM, Lee Spector <span dir="ltr"><<a href="mailto:lspector@hampshire.edu">lspector@hampshire.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
Jesse,<br>
<br>
You've got several near misses there, and there are several ways to do what you want. My first impulse is:<br>
<br>
(map #(+ % 5)<br>
(map first m))<br>
<br>
=> (90 97 71 85 55 90 71 42 108 39 118)<br>
<br>
Reading from the inside out, it maps first down m to produce a list of all the pitches (the first elements of the notes in your melody). Then it maps a function down that list of pitches. That function is specified anonymously, using the #() syntax, and it is the function that returns the result of calling + on its argument (%) and 5.<br>
<br>
In place of #(+ % 5) you could write, if you like, (fn [x] (+ x 5)).<br>
<br>
Of course, you could use a variable there in place of the 5.<br>
<br>
If you don't like the nesting you could do something like:<br>
<br>
(let [pitches (map first m)]<br>
(map #(+ % 5) pitches))<br>
<br>
And there are many other options. Here's a particularly weird one just for the heck of it:<br>
<br>
(->> (map first m)<br>
(map #(+ % 5)))<br>
<br>
-Lee<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
On Nov 17, 2011, at 12:05 PM, Jesse French wrote:<br>
<br>
> Hi all,<br>
><br>
> I'm trying to figure out how to map some simple functions along a vector, and having trouble due to my lack of understanding of how map works.<br>
><br>
> (def m<br>
> [[85 1]<br>
> [92 5/16]<br>
> [66 15/16]<br>
> [80 1/8]<br>
> [50 1/8]<br>
> [85 1/4]<br>
> [66 13/16]<br>
> [37 1/16]<br>
> [103 1/8]<br>
> [34 1/8]<br>
> [113 7/16]]<br>
><br>
> My goal is to map a '+ x' down the first value of this vector.<br>
><br>
> Even<br>
> (map first (map inc m))<br>
> doesn't work, when I would like to be doing something like<br>
> (map first (map (+ m x))<br>
> or<br>
> (map (+ (map first m) x))<br>
><br>
><br>
> (def p [100 15 29 7 63 59 44 72])<br>
> (map inc p)<br>
> This works, so I'm assuming my problem is with the syntax of how I'm nesting them.<br>
><br>
><br>
> Any thoughts?<br>
><br>
> Jesse<br>
><br>
> _______________________________________________<br>
> Cs254f11 mailing list<br>
> <a href="mailto:Cs254f11@lists.hampshire.edu">Cs254f11@lists.hampshire.edu</a><br>
> <a href="https://lists.hampshire.edu/mailman/listinfo/cs254f11" target="_blank">https://lists.hampshire.edu/mailman/listinfo/cs254f11</a><br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Lee Spector, Professor of Computer Science<br>
Cognitive Science, Hampshire College<br>
893 West Street, Amherst, MA 01002-3359<br>
<a href="mailto:lspector@hampshire.edu">lspector@hampshire.edu</a>, <a href="http://hampshire.edu/lspector/" target="_blank">http://hampshire.edu/lspector/</a><br>
Phone: <a href="tel:413-559-5352" value="+14135595352">413-559-5352</a>, Fax: <a href="tel:413-559-5438" value="+14135595438">413-559-5438</a><br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Cs254f11 mailing list<br>
<a href="mailto:Cs254f11@lists.hampshire.edu">Cs254f11@lists.hampshire.edu</a><br>
<a href="https://lists.hampshire.edu/mailman/listinfo/cs254f11" target="_blank">https://lists.hampshire.edu/mailman/listinfo/cs254f11</a><br>
</div></div></blockquote></div><br>