Note that there are some explanatory texts on larger screens.

plurals
  1. POMacro doesn't work in the function
    primarykey
    data
    text
    <p>I have problems with following code: <a href="http://lisper.ru/apps/format/96" rel="nofollow noreferrer">http://lisper.ru/apps/format/96</a></p> <p>The problem is in "normalize" function, which does not work.<br> It fails on the fifth line: <code>(zero-p a indexes i)</code></p> <pre><code>(defun normalize (a &amp;optional indexes i) "Returns normalized A." (progn (format t "Data=~A ~A ~A" a indexes i) (if (zero-p a indexes i) a ;; cannot normalize empty vector (let* ((mmm (format t "Zero?=~a" (zero-p a indexes i))) (L (sqrt (+ (do-op-on * a :x a :x indexes i indexes i) (do-op-on * a :y a :y indexes i indexes i) (do-op-on * a :z a :z indexes i indexes i)))) (mmm (format t "L=~a" L)) (L (/ 1D0 L)) (mmm (format t "L=~a" L))) ; L=1/length(A) (make-V3 (* (ref-of a :x indexes i) l) (* (ref-of a :y indexes i) l) (* (ref-of a :z indexes i) l)))))) </code></pre> <p>in function "normalize" I call the macro "zero-p", which in turn calls macro "ref-of", which is the last in the chain.</p> <pre><code>(defmacro zero-p (v &amp;optional indexes index) "Checks if the vector is 'almost' zero length." `(and (&lt; (ref-of ,v :x ,indexes ,index) *min+*) (&lt; (ref-of ,v :y ,indexes ,index) *min+*) (&lt; (ref-of ,v :z ,indexes ,index) *min+*) (&gt; (ref-of ,v :x ,indexes ,index) *min-*) (&gt; (ref-of ,v :y ,indexes ,index) *min-*) (&gt; (ref-of ,v :z ,indexes ,index) *min-*))) </code></pre> <p>Here is ref-of:</p> <pre><code>(defmacro ref-of (values coordinate &amp;optional indexes index) "Please see DATA STRUCTURE for details." (if indexes (cond ((eq coordinate :x) `(aref ,values (aref ,indexes ,index))) ((eq coordinate :y) `(aref ,values (+ 1 (aref ,indexes ,index)))) ((eq coordinate :z) `(aref ,values (+ 2 (aref ,indexes ,index)))) (T (error "The symbol ~S is not :X, :Y or :Z." coordinate))) (cond ((eq coordinate :x) `(aref ,values 0)) ((eq coordinate :y) `(aref ,values 1)) ((eq coordinate :z) `(aref ,values 2)) (T (error "The symbol ~S is not :X, :Y or :Z." coordinate))))) </code></pre> <p>Also, in "normalize" I call the macro "do-op-on", which calls "ref-of" as well.</p> <pre><code>(defmacro do-op-on (op name1 coord1 name2 coord2 &amp;optional is1 i1 is2 i2) "Example: (do-op-on * A :x B :y i n) == A[i[n]].x*B.y" `(,op (ref-of ,name1 ,coord1 ,is1 ,i1) (ref-of ,name2 ,coord2 ,is2 ,i2))) </code></pre> <p>As a result, instead of having this: <code>(aref some-array 0)</code> I have <code>(aref NIL NIL)</code> which is created in "ref-of".</p> <p>I suppose that I lose the symbol A from the call <code>(normalize A)</code>. I just feel that the symbol does not survive the macroexpanson. The thing is, macroexpansoin works in REPL for each macro independently.</p> <p>Can anyone explain where is the mistake?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload