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
'require' finds a .clj file in your classpath (which must define a
matching namespace) and loads it into Clojure.
'refer' brings definitions from some other already-loaded namespace into
your current namespace.
'use' does both in one step (use can use the :verbose flag to see it do
this)
All of these are for working with namespaces defined via Clojure code.
'import' is different in that it's only for dealing with .class files.
--Chouser
Am 20.12.2008 um 17:25 schrieb chris:
> I am unclear as to the difference between refer, import use, and
> require.
require loads a lib from the classpath. The you can
access the public names of the lib's namespace via
full qualified names.
(require 'foo.bar)
(foo.bar/baz "Hurray")
refer let's you refer an already require'd namespace,
so you can access the names directly.
(require 'foo.bar)
(refer 'foo.bar)
(baz "Hurray")
use is basically a require followed by a refer.
(use 'foo.bar)
(baz "Hurray")
alias can be used to introduce an alias for a require'd
namespace.
(require 'foo.bar)
(alias 'fb 'foo.bar)
(fb/baz "Hurray")
import is a "refer for classes". It is a direct translation
of the Java import.
w/o import:
(new java.io.BufferedReader ...)
w/ import:
(import '(java.io BufferedReader))
(new BufferedReader ...)
However these are all very low-level. The preferred
way is to use the :keyword notation in the ns macro.
(ns my.name.space
(:require
[foo.bar :as fb])
(:import
(java.io BufferedReader)))
(fb/baz "Hurray")
(new BufferedReader ...)
There are lots of other options :exclude, :only, ...
Hope this helps.
Sincerely
Meikel
Instead of require call use and should get you what you want.
On Dec 20, 2008 9:15 AM, "chris" <cnue...@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...
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,...
A:
On Sat, Dec 20, 2008 at 5:40 PM, Chouser <cho...@gmail.com> wrote:
> 'require' finds a .clj file in your classpath (which must define a
> matching namespace) and loads it into Clojure.
>
> 'refer' brings definitions from some other already-loaded namespace into
> your current namespace.
>
> 'use' does both in one step (use can use the :verbose flag to see it do
> this)
>
> All of these are for working with namespaces defined via Clojure code.
> 'import' is different in that it's only for dealing with .class files.
>
> --Chouser
Good material for the FAQ, no?
Or maybe just the docs. Regardless, this is a good explanation.
--
Venlig hilsen / Kind regards,
Christian Vest Hansen.
As far as I can tell, libs aren't really documented anywhere (besides
in the docs strings for 'ns' and the various helper function). If
I've missed it somewhere, please correct me, but It probably belongs
at http://clojure.org/namespaces
--Chouser
Am 21.12.2008 um 00:28 schrieb Chouser:
> As far as I can tell, libs aren't really documented anywhere (besides
> in the docs strings for 'ns' and the various helper function). If
> I've missed it somewhere, please correct me, but It probably belongs
> at http://clojure.org/namespaces
There is an empty http://clojure.org/libs at the moment.
So I guess Rich is working on it. On the wiki there is also
a section but it's out dated and no very comprehensive.
Sincerely
Meikel