What's in *your* user.clj?

346 views
Skip to first unread message

wlr

unread,
Nov 20, 2008, 10:03:47 AM11/20/08
to Clojure
An old tradition for emacs users is to publicize the contents of
their .emacs file. (For non-emacs folks, code in .emacs is run as
emacs itself starts up allowing emacs to run tailored to the
preferences of the user.)

As stated in http://clojure.org/getting_started if user.clj is found
on the classpath it will be autoloaded at clojure startup. Answers to
the subject question will perhaps change as users and clojure mature
together, but for now will you divulge (some of) your user.clj?

So far for me: user.clj is empty

Meikel Brandmeyer

unread,
Nov 20, 2008, 10:10:07 AM11/20/08
to Clojure
Hi,

On 20 Nov., 16:03, wlr <geeked...@gmail.com> wrote:
> An old tradition for emacs users is to publicize the contents of
> their .emacs file. (For non-emacs folks, code in .emacs is run as
> emacs itself starts up allowing emacs to run tailored to the
> preferences of the user.)
>
> As stated inhttp://clojure.org/getting_startedif user.clj is found
> on the classpath it will be autoloaded at clojure startup. Answers to
> the subject question will perhaps change as users and clojure mature
> together, but for now  will you divulge (some of) your user.clj?
>
> So far for me: user.clj is empty

In mine, I have (defn bye [] (java.lang.System/exit 0)),
since I have sometimes problems with <C-d> and <C-c>
on Windows. (Probably the short-cut is different...)

Sincerely
Meikel

Chouser

unread,
Nov 20, 2008, 10:34:37 AM11/20/08
to clo...@googlegroups.com
On Thu, Nov 20, 2008 at 10:03 AM, wlr <geek...@gmail.com> wrote:
>
> As stated in http://clojure.org/getting_started if user.clj is found
> on the classpath it will be autoloaded at clojure startup. Answers to
> the subject question will perhaps change as users and clojure mature
> together, but for now will you divulge (some of) your user.clj?
>
> So far for me: user.clj is empty

I used to use user.clj for the following, but that doesn't always work
right (did it have something to do with *print-length* not being bound
for clojure.lang.Script? I'm don't quite remember...) So anyway, I
have a little shell script that runs clojure for me with the right
classpath and, when launching a REPL, with ~/.clojurerc.clj on its
command line. In .clojurerc.clj, I have:

(import '(java.io LineNumberReader InputStreamReader PushbackReader)
'(java.lang.reflect Modifier Method Constructor)
'(clojure.lang RT))

(set! *print-length* 103)

(defn show
([x] (show x nil))
([x i]
(let [c (if (class? x) x (class x))
items (sort
(for [m (concat (.getFields c)
(.getMethods c)
(.getConstructors c))]
(let [static? (bit-and Modifier/STATIC
(.getModifiers m))
method? (instance? Method m)
ctor? (instance? Constructor m)
text (if ctor?
(str "(" (apply str (interpose ", "
(.getParameterTypes m))) ")")
(str
(if (pos? static?) "static ")
(.getName m) " : "
(if method?
(str (.getReturnType m) " ("
(count (.getParameterTypes m)) ")")
(str (.getType m)))))]
[(- static?) method? text (str m) m])))]
(if i
(last (nth items i))
(do (println "=== " c " ===")
(doseq [[e i] (map list items (iterate inc 0))]
(printf "[%2d] %s\n" i (nth e 2))))))))

*print-length* is documented elsewhere.
show works like this:

user=> (show Object) ; give it a class
=== java.lang.Object ===
[ 0] ()
[ 1] equals : boolean (1)
[ 2] getClass : class java.lang.Class (0)
[ 3] hashCode : int (0)
[ 4] notify : void (0)
[ 5] notifyAll : void (0)
[ 6] toString : class java.lang.String (0)
[ 7] wait : void (0)
[ 8] wait : void (1)
[ 9] wait : void (2)
nil
user=> (show Object 1) ; a class and a method number to see details
#<Method public boolean java.lang.Object.equals(java.lang.Object)>
user=> (show {}) ; or give it an instance
=== clojure.lang.PersistentHashMap ===
[ 0] static EMPTY : class clojure.lang.PersistentHashMap
[ 1] static applyToHelper : class java.lang.Object (2)
[ 2] static create : class clojure.lang.PersistentHashMap (1)
[ 3] static create : class clojure.lang.PersistentHashMap (1)
[ 4] static create : class clojure.lang.PersistentHashMap (1)
[ 5] static create : class clojure.lang.PersistentHashMap (2)
[ 6] static create : interface clojure.lang.IPersistentMap (1)
[ 7] (interface clojure.lang.IPersistentMap, int, interface
clojure.lang.PersistentHashMap$INode)
[ 8] applyTo : class java.lang.Object (1)
[ 9] assoc : interface clojure.lang.Associative (2)
...

It's like interactive javadoc, without all those distracting English
descriptions of things. :-)

--Chouser

bc

unread,
Nov 20, 2008, 2:46:26 PM11/20/08
to Clojure
Hi Chouser,

On Nov 20, 7:34 am, Chouser <chou...@gmail.com> wrote:
> On Thu, Nov 20, 2008 at 10:03 AM, wlr <geeked...@gmail.com> wrote:
>
> > As stated inhttp://clojure.org/getting_startedif user.clj is found
> > on the classpath it will be autoloaded at clojure startup. Answers to
> > the subject question will perhaps change as users and clojure mature
> > together, but for now  will you divulge (some of) your user.clj?
>
> > So far for me: user.clj is empty
>
> I used to use user.clj for the following, but that doesn't always work
> right (did it have something to do with *print-length* not being bound
> for clojure.lang.Script? I'm don't quite remember...)  So anyway, I
> have a little shell script that runs clojure for me with the right
> classpath and, when launching a REPL, with ~/.clojurerc.clj on its
> command line.  In .clojurerc.clj, I have:
>
> (import '(java.io LineNumberReader InputStreamReader PushbackReader)
>         '(java.lang.reflect Modifier Method Constructor)
>         '(clojure.lang RT))
>
> (set! *print-length* 103)
>
> (defn show
>   ([x] (show x nil))
>   ([x i]
>       (let [c (if (class? x) x (class x))
>             items (sort

Very nice! However, shouldn't the modification to *print-length* be
inside a binding - e.g.:

(defn show
([x] (show x nil))
([x i]
(binding [*print-length* 103]
(let [c (if (class? x) x (class x))
items (sort

--
Bill Clementson

Chouser

unread,
Nov 20, 2008, 3:27:23 PM11/20/08
to clo...@googlegroups.com
On Thu, Nov 20, 2008 at 2:46 PM, bc <bill...@gmail.com> wrote:
>
> Very nice! However, shouldn't the modification to *print-length* be
> inside a binding - e.g.:

Oh, no, those are two independent settings. 'show' is not helped much
the the constrained *print-length* since it does its own looping and
only over concrete things like method lists -- no infinite seqs there.

No, the *print-length* is set for the whole REPL context to save
myself from pain when I accidentally evaluate the equivalent of
(iterate inc 0) at the prompt.

--Chouser

Bill Clementson

unread,
Nov 20, 2008, 3:31:15 PM11/20/08
to clo...@googlegroups.com

Ah, ok - I thought the *print-length* mod was related to the 'show' function.

- Bill

bc

unread,
Nov 20, 2008, 4:51:02 PM11/20/08
to Clojure


On Nov 20, 12:31 pm, "Bill Clementson" <billc...@gmail.com> wrote:
> On Thu, Nov 20, 2008 at 12:27 PM, Chouser <chou...@gmail.com> wrote:
>
> > On Thu, Nov 20, 2008 at 2:46 PM, bc <billc...@gmail.com> wrote:
>
> >> Very nice! However, shouldn't the modification to *print-length* be
> >> inside a binding - e.g.:
>
> > Oh, no, those are two independent settings.  'show' is not helped much
> > the the constrained *print-length* since it does its own looping and
> > only over concrete things like method lists -- no infinite seqs there.
>
> > No, the *print-length* is set for the whole REPL context to save
> > myself from pain when I accidentally evaluate the equivalent of
> > (iterate inc 0) at the prompt.
>
> Ah, ok - I thought the *print-length* mod was related to the 'show' function.

I thought the "show" code was so useful, I've added a command key to
call it from emacs/slime. I did the same for cgrand's javadoc
function. Details here:
http://bc.tech.coop/blog/081120.html

- Bill
Reply all
Reply to author
Forward
0 new messages