On Oct 1, 2008, at 8:22 AM, Yan Liu wrote:
> (define loopinside
> (lambda(y ymax x)
> (if (< y ymax)
> (begin (make block (center (+ 0.5 x) (+ 0.5 y)) (size 1 1 infinity)
> (material (make dielectric (epsilon (read i)))))
> (set! y(+ y 1))

This does not return a list of materials.  In fact, it does not return  
anything useful.  The problem is that your loop body doesn't *do*  
anything with the block it creates.

Let me make an analogy.  Suppose you wanted to sum n numbers i=1 to n,  
in a C program.  The analogue of your loop above would be to write:
        for (i = 1; i <= n; ++i)
                i;
This is a perfectly valid C program, but it doesn't compute the sum.   
The command "i;" just evaluates i but doesn't do anything with the  
result.  Your code has the same problem.

If you want to do it in a traditional, imperative style (which is what  
the "do" loop construct is for), then you need to have some variable  
that will hold your list of objects, and then on each iteration of the  
loop add your object to the list with "cons" and "set!"

A more natural style (for Scheme) is to use "map":

        (map (lambda (y) (make block ....))
                   (arith-sequence y-min y-step num-y))

"map" returns a list and is a basic tool in Scheme to create one list  
from another.

Steven

_______________________________________________
meep-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss

Reply via email to