Dear Dr. Johnson and every meep user: I am sorry that I am not very familiar with Scheme Programming. I have tried to make the change as you described but the loop would not return a list of materials.
There is some other explanations on the using of "map" on mailing list. But that seems different with my 2D data reading case. I know that scheme is based on lisp(list processing). But I feel confused with my problem. I think my program is still with the questions you mentioned before. I have tried two ways: 1) (define loopinside (lambda(y ymax x) (if (< y ymax) (begin (set! geometry(make block (center (+ 0.5 x) (+ 0.5 y)) (size 1 1 infinity) (material (make dielectric(epsilon 12))))) (set! y(+ y 1)) (loopinside y ymax x))))) (define loopoutside (lambda (x xmax y ymax) (if (< x xmax) (begin (loopinside y ymax x) (set! x (+ x 1)) (loopoutside x xmax y ymax))))) when I use (loopoutside -110 110 -65 65) the it seems there is still nothing returns Backtrace: In current input: 46: 0* [run-until 200 #<procedure #f (to-do)> #<procedure #f (to-do)>] ?: 1* (if (null? fields) (init-fields)) ?: 2 [init-fields] ?: 3* (if (null? structure) (init-structure k-point)) ?: 4 [init-structure #f] ... ?: 5 (set! structure (make-structure (infer-dimensions k) s ...)) ?: 6* [make-structure 2 #(222 132 1.0e-20) #(0 0 0) 1 #t 1.0e-4 100000 #f ...] I have tried to use map, same problem occurs <unnamed port>: In procedure vector-ref in expression (make-structure (infer-dimensions k) s ...): <unnamed port>: Wrong type argument in position 1: #f ABORT: (wrong-type-arg) I am not very clear on how to use 'cons and set!' or 'map' to finish my 2D data reading task in meep Would you please describe it more clearly? Thanks very much! Best Regards! 2008/10/2 Steven G. Johnson <[EMAIL PROTECTED]> > 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 > -- Thanks! Yan Liu Department of Biomedical Engineering, Huazhong University of Science and Technology Phone: (86)-130-7129-6471 Personal Website: sites.google.com/site/yanliurf -- Thanks! Yan Liu Department of Biomedical Engineering, Huazhong University of Science and Technology Phone: (86)-130-7129-6471 Personal Website: sites.google.com/site/yanliurf
_______________________________________________ meep-discuss mailing list [email protected] http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss

