Note that there are some explanatory texts on larger screens.

plurals
  1. POClojure macro Instantiation Exception
    text
    copied!<p>I have a macro which works in the repl, and it seems to work in my code outside the <code>let</code> and also inside the <code>let</code> as follows. However it also breaks and I have no idea why. The macro basically just takes the first arg as a function to call, and puts <code>into-array</code> before the last set of arguments, and it adds the class of the final non-collection argument as a parameter to into-array, if it is in the java class heirarchy.</p> <pre><code>(defmacro jvar [method &amp; args] (let [lastargs (last args) evaled-lastargs (eval lastargs)] (if (coll? evaled-lastargs) (let [firstargs (butlast args) klass (eval (last firstargs)) supset (map #(supers (class %)) evaled-lastargs) common (apply intersection #{klass} supset)] (if (seq common) `(~method ~@(butlast firstargs) (into-array ~(first common) ~lastargs)) `(~method ~@firstargs (into-array ~lastargs)))) (throw (Error. "Last argument must be defn."))))) </code></pre> <p>Usages: In Repl: </p> <pre><code>jfxcircles.core&gt; (macroexpand '(jvar Group. Node [(Circle. 100)])) (new Group (clojure.core/into-array javafx.scene.Node [(Circle. 100)])) jfxcircles.core&gt; (jvar Group. Node [(Circle. 100)]) #&lt;Group Group@c26729e&gt; </code></pre> <p>In <code>let</code>: </p> <pre><code>(let [root (Group.) scene (Scene. root 800 600) ;etc. this is for JavaFX ... circ (Circle. 100) inner-group1 (jvar Group. [(Circle. 100)]) ; works inner-group2 (jvar Group. [circ]) ; Instantiation Exception inner-group3 (jvar Group. [(Rectangle. 100 100)]) ; works inner-group4 (jvar Group. [(Rectangle. (.getWidth scene) 100)]) ; Instantiation exception ) </code></pre> <p>So basically it won't compile under certain circumstances that should otherwise be the same, and I'm unable to do macroexpand because it won't compile. Any ideas?</p> <p>thanks</p>
 

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