[MWForum]Re: "map" ?
Daniel Ajoy
mwforum@lists.mathcats.com
Fri, 10 Jan 2003 21:43:13 -0500
On 10 Jan 2003 at 16:08, Jeff Knope wrote:
> This map thing you offered is intriguing. I think I understand the concept.
> But my Help lists don't show "map" as a primitive. I got my MWPro direct
> from LCSI less than a year ago. Is there a more recent version? When I
> copied your line into the Command Center and ran it, I got "I don't know how
> to map." Have you written a mapping procedure? It shouldn't be too hard to
> do.
>
Hi Jeff,
map is part of MSWLogo and UCBLogo but not of Microworlds Pro.
these functions (UCBLogo has others) are called higher-order
functions because they receive as input not only numbers, words
or lists to work with, but other functions. These higher-order
functions use these regular input functions to apply them in
different ways or transform them in other functions.
I like them a lot, and have created many of my own.
Here is a simple implementation of map:
to ?
op :eachone:
end
to instantiate :f: :eachone:
op run :f:
end
to map :f: :l:
if empty? :l: [op []]
op fput (instantiate :f: first :l:) map :f: bf :l:
end
show map [minus ? - 1] [1 2 3]
0 -1 -2
show map [? * ?] [1 2 3]
1 4 9
show map [map [minus ?] ?] [[1 2] [3 4] [5 6]]
[-1 -2] [-3 -4] [-5 -6]
Daniel
OpenWorld Learning