nm, I need to use 'use'.

I am unclear as to the difference between refer, import use, and
require.

Chris

On Dec 20, 9:15 am, chris <cnuern...@gmail.com> wrote:
> That helped, thanks Christophe.
>
> I have one more problem:
>
> I put it in a util file, under a util namespace:
>
> (ns lambinator.util)
>
> (defmacro sets! [vars & rest]
>   `(do ~@(map (fn [flds] `(set! (. ~vars ~(first flds)) ~(second
> flds))) (apply array-map rest))))
>
> Now I want to use it outside that namespace.  It seems that I have to
> do two things when I load from a jar...
>
> (require 'lambinator.util)
>
> (lambinator.util/sets! c fill GridBagConstraints/VERTICAL weightx 1.5)
>
> How do I use the function/macro outside the namespace it was created
> in without prefixing it with lambinator.util?  Import, require don't
> seem to do what I want...
>
> Chris
>
> On Dec 20, 12:28 am, Christophe Grand <christo...@cgrand.net> wrote:
>
> > chris a écrit :
>
> > > Hello, I am gearing up to write some swing code, specifically some
> > > stuff where I want to use the grid bag layout system, and I remember
> > > something I hated about java:
>
> > > --c.fill = GridBagConstraints.HORIZONTAL;
> > > c.weightx = 0.5;
> > > c.gridx = 2;
> > > c.gridy = 0;
> > > --
>
> > > You repeated c all over the place so you didn't dare name it something
> > > reasonable.
>
> > > I noticed in some closure code this looks about the same (actually
> > > worse):
> > > (set! (.fill c) GridBagConstraints/HORIZONTAL)
> > >     (set! (.anchor c) GridBagConstraints/PAGE_END)
> > >     (set! (.weightx c) 1.0)
> > >     (set! (.weighty c) 1.0)
>
> > Your sets! macro seems a good idea to me.
>
> > When an object provides proper accessors, you can write:
>
> > (doto c
> >   (.setFill GridBagConstraints/HORIZONTAL)
> >   (.setAnchor GridBagConstraints/PAGE_END)
> >   (.setWeightx 1.0)
> >   (.setWeighty 1.0))
>
> > But in your case, the only way to use doto I can think of is:
>
> > (doto c
> >   (-> .fill (set! GridBagConstraints/HORIZONTAL))
> >   (-> .anchor (set! GridBagConstraints/PAGE_END))
> >   (-> .weightx (set! 1.0))
> >   (-> .weighty (set! 1.0)))
>
> > which does not repeat c but is even slightly longer than the naive
> > sequence of set!.
>
> > I think that you could remove some parens from your macro form to just
> > write:
>
> > (sets! c
> >   fill GridBagConstraints/HORIZONTAL
> >   weightx 1.0)
>
> > (I think it's a more idiomatic form, see cond or bindings: pairs aren't
> > paired together.)
>
> > (defmacro sets! [vars & rest]
> >   `(do ~@(map (fn [flds] `(set! (. ~vars ~(first flds)) ~(second flds)))
> > (apply array-map rest))))
>
> > Christophe
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to