Christopher Howard <cmhowa...@alaska.edu> writes:
> Is there a trick for "pre-expanding" some of the arguments passed to a
> macro? Say you wanted to do this
>
> code:
> --------
> (def swing-imports '(javax.swing JFrame JButton ImageIcon JPanel))
>
> (ns example.myprogram
>   (:import swing-imports))
>   ...
> --------
>
> ns will complain that it can't find the "swing-imports" class.
>
> I've been trying various things I thought might work (like backtick
> evaluation and evals) but haven't made progress.


Well, the namespace macro would have to support this. And the problem
is, that your (def swing-imports) form is likely to be in a different
namespace (probably user) from example.myprogram because the ns form
changes namespace.

As a little toy, I wrote a functional and extensible namespace form at
one point....

https://github.com/phillord/namespace-experiments

Given this namespace...

(ns namespace.imports
  (:use namespace.namespace))

(defn tawny-read []
  (use-only
   (req tawny.read)
   'defread))



You could define a new namespace like this....

(newnamespacet
 bob
 (req namespace.imports)
 (namespace.imports/tawny-read))


So, first we require the import namespace, then we call a function which
applies a set of requires. It would also allow doing the same as your
request -- although in my case, I wanted to put the imports into an
independent file.

It's nice, but doesn't really work, because doesn't work sensibly
because you have to require the "newnamespace" function before you use
it. The Clojure ns avoids this by being in clojure.core.

Anyway, if you really want to do this, don't try and fix the ns macro,
but use the clojure.core/import macro after the fact.

Phil

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to