schemeguilemeep

What does this scheme error tell me?


There exists an elecomagnetic simulator called meep which provides as a front end in the form of a guile interpreter. The simulator consists of a bunch of scheme macros.

I am trying to figure out what the following error means. The code is taken from the tutorial. When I wrap the tutorial in a procedure I get an runtime error and I am not sure what the interpreter (guile) is telling me.

Not Working Code

(define diffthick
  (lambda (n) ; n doesn nothing
    (
     (set! geometry-lattice (make lattice (size 16 8 no-size)))
     (set! geometry (list
                      (make block (center 0 0) (size infinity 1 infinity)
                            (material (make dielectric (epsilon 12))))))
     (set! sources (list
                     (make source
                           (src (make continuous-src (frequency 0.15)))
                           (component Ez)
                           (center -7 0))))
     (set! pml-layers (list (make pml (thickness 1.0))))
     (set! resolution 10)
     (run-until 200
                (at-beginning output-epsilon)
                (at-end output-efield-z))
     )
    )
  )
(diffthick 3)

Working Code (without the procedure)

(set! geometry-lattice (make lattice (size 16 8 no-size)))
(set! geometry (list
                (make block (center 0 0) (size infinity 1 infinity)
                      (material (make dielectric (epsilon 12))))))
(set! sources (list
               (make source
                 (src (make continuous-src (frequency 0.15)))
                 (component Ez)
                 (center -7 0))))

(set! pml-layers (list (make pml (thickness 1.0))))
(set! resolution 10)
(run-until 200
           (at-beginning output-epsilon)
           (at-end output-efield-z))

Error

creating output file "./eps-000000.00.h5"...
creating output file "./ez-000200.00.h5"...
run 0 finished at t = 200.0 (4000 timesteps)

Backtrace:
In standard input:
  21: 0* [diffthick 3]
   3: 1  [#<unspecified> #<unspecified> #<unspecified> ...]

standard input:3:5: In expression ((set! geometry-lattice #) (set! geometry #) (set! sources #) ...):
standard input:3:5: Wrong type to apply: #<unspecified>
ABORT: (misc-error)

Working

-----------
creating output file "./eps-000000.00.h5"...
creating output file "./ez-000200.00.h5"...
run 0 finished at t = 200.0 (4000 timesteps)

At the end of the day I feel like something is being evaluated twice. But I am not sure what that thing is.


Solution

  • The error says the code is trying to apply the result of (set! geometry-lattice #) as if it's a function, but the set! results in #<unspecified> instead. This happens because the series of set!s are wrapped in parens.

    You're probably looking for

    (begin
      (set! geometry-lattice ...)
      ...
      (run-until ...))
    

    Or just get rid of that extra pair of parens, since lambda bodies are implicitly wrapped in a begin.