On Tue, 14 Nov 2006, Pascual Muñoz Muñoz wrote:
I've been looking to the 'loop' howto on the wiki, but I cannot manage
how to make a loop that makes a list of objects in different positions
and with different widths, depending on the loop variable.
I've tried several things, the one making more sense to me (but not
working) is (not changing the width of the slices):
(set! geometry
(list
(make block (center 0 0) (size W L)
(material (make dielectric (index nde))))
(do ((x (* -1 Gp) (+ x 1))) ((> x Gp))
(make block (center 0 (* x 0.12)) (size W 0.12)
(material (make dielectric (index
1.0)))) ) ) )
A "do" loop does not return a list of objects, which is what you want to
do here.
To create a list, the easiest thing is to use "map". For example,
(set! geometry
(cons
(make block (center 0 0) (size W L)
(material (make dielectric (index nde))))
(map
(lambda (x)
(make block (center 0 (* x 0.12)) (size W 0.12)
(material (make dielectric (index 1.0)))))
(arith-sequence (- Gp) 1 (round (+ (* 2 Gp) 1))))))
Of course, this does not change the width of the slices (they are all W),
but neither does your example. You can easily substitute some arbitrary
function of x here.
(Note that (cons a B) prepends an element "a" to the list "B".)
Steven
_______________________________________________
meep-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss