On Fri, 29 Jun 2007, adrian wrote:
> the first block wouldn't show up in the result but only the last block.
> can anyone give me any hint to improve this and tell me how to use map
> to establish more than two objects, which shapes are arbitrary?
What you are trying to do is to have 'map' apply a function to a list of
numbers, where for each number the function returns two or more objects,
and have the result as a single list of objects.
To do this, you need to use two steps:
1) first, map your function to the list of input numbers, and have your
function return a *list* of objects. The result of 'map' will then be a
list of lists.
2) concatenate all of the lists to produce a single list.
Let me give a simple example, without using geometric objects.
Suppose you want to take a list of numbers L = (x y z) and return the list
(x x+1 x+2 y y+1 y+2 z z+1 z+2). That is, each original number you want
to replace with three consecutive numbers.
You would do this as follows. First, produce a list of lists:
(map (lambda (x) (list x (+ x 1) (+ x 2)))
L)
If L = (1 7 3), this returns the following list of lists:
((1 2 3) (7 8 9) (3 4 5))
However, this is not quite what you want -- you want to combine the lists
into a single list. You can combine two or more lists into a single list
by using the "append" function, so we just have to apply this function to
the result of our 'map'. We do this by using 'apply':
(apply append (map (lambda (x) (list x (+ x 1) (+ x 2))) L))
which returns:
(1 2 3 7 8 9 3 4 5)
as desired.
Steven
_______________________________________________
meep-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss