The Map
Block (Teacher's Choice)
- For future years: I think these pages are getting too long for one page each. --MF
- For now, there are a few comments to read below. --MF
- GH Feedback 10/30/15: Minor issue, perhaps nitpicky, but I wish one of the list elements used in MAP ROUND were something that got rounded up. A student who is unclear on the difference between ROUND and FLOOR could get confused.
The
block takes two inputs: a function (with a blank input slot) and a list, and it reports a new list, in which each item is the result of running an item of the input list through the function. For example:



You write the function that describes the change, and map
applies that function to each item in the input list and reports the list of values reported by the function.
Transposing Music
- BH: ...just starting with the Unicode example would be okay, although really we should have, as Paul always says, a problem that kids will want to solve and /then/ talk about how to combine HOFs to solve it.
- This is supposed to be that problem kids want to solve. (Hopefully!) I cleaned it up. Keep? --MF
The simplest bits of a scales project could also work. Two scales (I'd recommend major and double-harmonic only because they give cool variety and, btw, validate an interesting group of kids), a transposer (map), and something that plays them (for-each). --PG
I think this cannot be done with map... -MF
Now, you'll transpose songs, which have lists of lists of note pitches and beats.
- Open your U3L1-PlaySong project from Lab 1.
-
Create a reporter block that transposes a list of sounds, where each list item is a list with the sound's note and duration. Your block should take as input a list with the song data and a number indicating how much to transpose the song.
map
will be helpful here.
- Musical scales are sets of notes ordered by pitch. For example, this is the C Major scale and the Snap! note numbers:
- Create a block that plays a scale.
- Create a reporter that generates an arpeggio of a scale...
Mapping Plurals into Sentence Builder
- Open "U3L1-SentenceBuilder" from Lab 1.
- Modify your
noun phrase
block so that half of the time it uses a plural noun.
- Note that when you use a plural noun, the article can not be "a" because "a" implies that it is a singular noun. Devise a solution.
Drawing 3D Shapes
Lab1's last page, draw shape, has lots of numbers, but we're doing something with them. If we used MAP over the vertices of A to translate it, or dilate it, that would be ok. I actually thought that was here somewhere, but couldn't find it. That would require a slightly more complex "getting inside" the list operation, but the kids in their dialogue have already begun that thinking in draw shape. But when we get to the page on MAP, it applies arbitrary functions to arbitrary numbers for no apparent reason other than exercise.
Could you invent a MAP page that builds on draw shape, maybe translating or reflecting or dilating? You could exchange x and y coords and see what happens. A translation of, say, (20, 10) could look 3-D ish, especially if corners of the two were connected. So would a connecting an image and a dilation. --PG
You can use map
to translate coordinates on a plane.
- Open your "U3L2-DrawShape" project from Lab 2.
Use addition to translate the shape to different locations.
- Create a
shape zoo
block that uses your draw shape
block together with map
to draw the shape (given as an input list) at random places on the stage.
"U3L3-ShapeZoo"
Use multiplication to dilate the shape.
- Change your
shape zoo
block so that it dilates (re-scales) each shape by a random factor (for example, from .5 to 3).

What changes about a coordinate pair when it flips across the
x- or
y-axis?
- Adjust your
shape zoo
block so that it sometimes reflects (flips) the shape vertically and/or horizontally.
I found the 3D thing too difficult, and I have not gotten it working yet, so I made it a TIF. Someone please check that it's reasonable to ask this? --MF
-
Create a
draw 3D shape
block that takes a list of points as input and does the following:
- Draws the shape by calling your existing
draw shape
block
- Draws a second copy of the shape shifted 20 in the x direction and 10 in the y direction
- Connects the corresponding vertices (corners) of the two copies of the shape
-
Describe the result of this block:
- Build a block
move
that moves the letter A 37 units left and 23 units up.
- Make
move
more general, so that you can input how much you want to change each coordinate of the elements of A.
You can connect corresponding vertices for a 3-D effect.
Using Map
for Algebraic Functions
Alphie and Betty are talking about another example of using map
to compute some function of every item of a list:
Betty: That gray ring after the word "map" means a function goes in there. A function? Like in algebra? What about the function f defined by f(n) = 3n + 7?
Alphie: Well, I don't think the function has to be mathematical. We used
plural
with words. But let's try to put the function
f in there. First I need to build
f. Here you go:

Then we map
f over a list, like 2, 0, and 7:

and it works!
Betty: But I think I see an easier way. There's no need to name f. We leave the input in the expression blank, just like we did in join
.
Betty makes and clicks to see

Alphie: Let's see. 2 times 3 is 6. And then add 7. That's 13. Good, it worked!
"U3L3-FunctionPractice"
-
Practice: Write a block for the following function: g(n)=6n+5
-
For each of these problems, start with this block:
- Write a function for
map
that would report the list 3, 1, 8.
- Write a function for
map
that would report the list 4, 0, 14.
This question refers to these two lists:


Which of these statements are true?
Choose all that apply.

reports the list
{r, 5, b, i, 3, k, 2, 3, t, 6}.
Correct.

reports the list
{rabbit}.
No. The blank space is expecting a list as its input, but map
puts a single item from words and numbers
into that slot.

reports the list
{Augusta, Boise, Columbia, Des Moines}.
Correct.

reports the list
{A, B, C, D}.
No. You can find the first letter of a word, but not the first letter of a list.

reports the list
{Maine, Idaho, South Carolina, Iowa}.
No. This is kind of a trick question. What gets reported is actually a list of lists. The output is: {{Maine}, {Idaho}, {South Carolina}, {Iowa}}.