[Gsll-devel] Fwd: keeping m-variables in closures

Mirko Vukovic mirko.vukovic at gmail.com
Wed Aug 6 15:12:16 UTC 2008


Actually something else may be going on here, because the m-variable x can
be accessed later on.    I thought that maybe calls to lu-solve may
obliterate mmat and mrhs but that does not seem to be the case - I commented
those calls out, but mmat and mrhs are still nils.

Mirko


---------- Forwarded message ----------
From: Mirko Vukovic <mirko.vukovic at gmail.com>
Date: Wed, Aug 6, 2008 at 11:01 AM
Subject: keeping m-variables in closures
To: gsll-devel at common-lisp.net


Hello folks

(the following is not a showstopper, but I am just curious).

I am trying to define a closure (still doing LU decompositions and matrix
solutions), and would like to keep some of the variables around for further
processing.   Here is one example

(defun parallel-plate-equilibrium (eps0 T0 eps1- eps1+ eps2 T2
                   &key (q1 0d0))
  (letm ((dim 5)
     (mat (make-array (list dim dim)
                :element-type 'double-float
                :initial-contents
                (list (list 1d0 (1- eps0) 0d0 0d0 0d0)
                  (list (1- eps1-) 1d0 0d0 0d0 (0- eps1-))
                  (list 0d0 0d0 1d0 (1- eps1+) (0- eps1+))
                  (list 0d0 0d0 (1- eps2) 1d0 0d0)
                  (list (0- eps1-) 0d0 0d0 (0- eps1+) (+ eps1- eps1+)))))
     (mmat (matrix-double-float mat))
;;     (mmat0 mmat)
     (rhs (make-array dim
              :element-type 'double-float
              :initial-contents (list (st4 T0 eps0) 0d0 0d0
                          (st4 T2 eps2) q1)))
     (mrhs (vector-double-float rhs))
     (per (permutation dim))
     (res (vector-double-float dim))
     (0-vec (vector-double-float (make-array dim
                         :initial-element 0d0)))
     (x (vector-double-float dim)))
    (lu-decomp mmat per)
    (lu-solve mmat per mrhs x)
    (data x)
    (lambda (command)
      (case command
    ;; these two will fail because mmat, mrhs, mmat0 are nil
    ;;    (:solve (lu-solve mmat per mrhs x))
    ;;    (:check (gemv :notrans 1d0 mmat0 x 0d0 0-vec))
    (:mat mat)
    (:rhs rhs)
    (:temp (expt (/ (aref (data x) 4)
            +sigma+)
             0.25))
    (:fluxes (data x))))))


However, it seems that gsll's variables are discarded once the letm form is
done (as per documentation, and also with macroexpansion).  But the code for
letm mentions some "freers", which gave me hope that I can specify the freer
as NIL.  But I could not figure that one out quite yet.  So, is it possible
to save some of gsll's variables for later use?

Thanks,

Mirko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/gsll-devel/attachments/20080806/711a29b5/attachment.html>


More information about the gsll-devel mailing list