Clojure box - loading book examples from "Programming Clojure"

52 views
Skip to first unread message

dumb me

unread,
Jul 8, 2009, 2:55:04 AM7/8/09
to Clojure
Hi All,

I am a dumb around here. my first post among many to come :)

I setup clojurebox to work thru the book. I am a newbie to emacs and
to clojure. I don't mind the learning curve to emacs.

I am completely blank about configuring Clojurebox.
Here's what I want to do:

1) load all the code-examples and the related jar-files of the book -
when I load ClojureBox.

2) Where do I find the .emacs for Clojure Box? As I understand that I
will have to modify this file to include the libraries/folder-path. I
don't see one...

3) I have been trying to do (load-file
"code.examples.introduction.clj") [my home directory being c:\emacs
and the code folder inside the emacs folder.] and I always get the
File-not-found exception.

[ i did my share of trying to make clojure work from cygwin and even
windows command - failed to start clojure with all the libraries, had
to manually create a bat file to run. Then came the indentation part,
I have been typing away on one line, but is terribly messy.The biggest
obstacle is indentation. I know I can edit a file and reload it, but I
prefer it via the REPL]

I did read about an earlier post (http://groups.google.com/group/
clojure/browse_thread/thread/0bb49e6409f43f5d/cbf20098c83215d3) but I
didn't see an accepted solution to that.

-dumby

dumb me

unread,
Jul 8, 2009, 10:49:44 AM7/8/09
to Clojure

anyone? Has anyone worked on Clojure box with the book examples?
Last thing I tried was to load a single file (load-file "c:\emacs\code
\examples\introduction.clj") and what I get is the last program in
that file.

thanks.

Shawn Hoover

unread,
Jul 8, 2009, 2:02:12 PM7/8/09
to clo...@googlegroups.com
On Wed, Jul 8, 2009 at 2:55 AM, dumb me <dum...@gmail.com> wrote:

Hi All,

I am a dumb around here. my first post among many to come :)

I setup clojurebox to work thru the book. I am a newbie to emacs and
to clojure. I don't mind the learning curve to emacs.

I am completely blank  about configuring Clojurebox.
Here's what I want to do:

1) load all the code-examples and the related jar-files of the book -
when I load ClojureBox.

This requires putting the example source directly and all the jars into the Emacs Lisp variable swank-clojure-extra-classpaths (or writing some code to scoop them all up and generate a value to put in a variable). See the Customization section of the README.rtf that installs with Clojure Box. There should be a shortcut in the Start menu.
 
2) Where do I find the .emacs for Clojure Box? As I understand that I
will have to modify this file to include the libraries/folder-path. I
don't see one...

"C-x C-f ~/.emacs". More info in the Customization section of the README.rtf that installs with Clojure Box.
 
3) I have been trying to do (load-file
"code.examples.introduction.clj") [my home directory being c:\emacs
and the code folder inside the emacs folder.] and I always get the
File-not-found exception.

Once the classpath is set up correctly using the above techniques, in the REPL you can type (use 'code.examples.introduction) or leave off code. or code.examples. depending on what part you actually put on your classpath.
 
Shawn

Robert Campbell

unread,
Jul 8, 2009, 2:13:44 PM7/8/09
to clo...@googlegroups.com
1. Here is my .emacs I use for Clojure Box to load the Jars and add
the proper paths to your classpath:

(setq swank-clojure-extra-classpaths
'())
(add-to-list 'swank-clojure-extra-classpaths
"C:/Dev/clojure/clojure.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Dev/clojure-contrib/target/clojure-contrib-1.0-SNAPSHOT.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Dev/compojure/deps/jetty-6.1.16.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Dev/technomancy-clojure-http-client/src")

etc... just add directories and jars as needed

2. Your .emacs file would be here: C:\Documents and Settings\${your
username}\Application Data

3. I don't know about this one, but I had problems setting my home
directory. Even though I did it, it was still looking in C:\Documents
and Settings\${your username}\Application Data. Files there would load
fine.

Shawn Hoover

unread,
Jul 8, 2009, 2:14:37 PM7/8/09
to clo...@googlegroups.com
Oh, here's an example snippet I just saw from Daniel Lyon on another thread (note how it cleverly grabs all the jars from the ~/.clojure directory--you could add another one of these for another directory of jars):

(setq swank-clojure-extra-classpaths
      (cons "/Users/fusion/Projects/
Languages/Clojure/classes"
           (cons "/Users/fusion/Projects/Languages/Clojure"
                 (directory-files "~/.clojure" t "\.jar$"))))
(eval-after-load 'clojure-mode '(clojure-slime-config))
(setq swank-clojure-extra-vm-args '("-Dclojure.compile.path=/Users/
fusion/Projects/Languages/Clojure/classes"))

Shawn Hoover

unread,
Jul 8, 2009, 2:21:57 PM7/8/09
to clo...@googlegroups.com
Sorry, the snippet author was Daniel Lyons. Here's a link to the other thread: http://groups.google.com/group/clojure/browse_thread/thread/6198db7d82610293

Mani

unread,
Jul 8, 2009, 2:56:20 PM7/8/09
to Clojure
Thanks Shawn, Robert.
From Robert's post, I am bit confused here. I also read that .emacs is
in %appdata% folder (vista), but all I see is .emacs.d folder (which I
guess is for the emacs server). I tried creating one "C-x C-f
~/.emacs" - under my home-directory (C:\emacs). Should i just create
a .emacs under %appdata%/.emacs.d OR right under %appdata%?


thx again.


On Jul 9, 2:13 am, Robert Campbell <rrc...@gmail.com> wrote:
> 1. Here is my .emacs I use for Clojure Box to load the Jars and add
> the proper paths to your classpath:
>
> (setq swank-clojure-extra-classpaths
>       '())
> (add-to-list 'swank-clojure-extra-classpaths
>              "C:/Dev/clojure/clojure.jar")    
> (add-to-list 'swank-clojure-extra-classpaths
>              "C:/Dev/clojure-contrib/target/clojure-contrib-1.0-SNAPSHOT.jar")                                        
> (add-to-list 'swank-clojure-extra-classpaths
>              "C:/Dev/compojure/deps/jetty-6.1.16.jar")
> (add-to-list 'swank-clojure-extra-classpaths
>              "C:/Dev/technomancy-clojure-http-client/src")
>
> etc... just add directories and jars as needed
>
> 2. Your .emacs file would be here: C:\Documents and Settings\${your
> username}\Application Data
>
> 3. I don't know about this one, but I had problems setting my home
> directory. Even though I did it, it was still looking in C:\Documents
> and Settings\${your username}\Application Data. Files there would load
> fine.
>
>
>
> On Wed, Jul 8, 2009 at 8:02 PM, Shawn Hoover<shawn.hoo...@gmail.com> wrote:

Mani

unread,
Jul 8, 2009, 3:04:17 PM7/8/09
to Clojure
Robert? Is that all you have in your .emacs? I am looking to create
one from scratch.

I noticed that you have clojure / clojure-contrib jars in your .emacs,
but what about slime/swank settings? won't they be overridden by
Clojure Box -settings or other way - .emacs loading without slime/
swank? (taking a blind guess)




On Jul 9, 2:13 am, Robert Campbell <rrc...@gmail.com> wrote:
> 1. Here is my .emacs I use for Clojure Box to load the Jars and add
> the proper paths to your classpath:
>
> (setq swank-clojure-extra-classpaths
>       '())
> (add-to-list 'swank-clojure-extra-classpaths
>              "C:/Dev/clojure/clojure.jar")    
> (add-to-list 'swank-clojure-extra-classpaths
>              "C:/Dev/clojure-contrib/target/clojure-contrib-1.0-SNAPSHOT.jar")                                        
> (add-to-list 'swank-clojure-extra-classpaths
>              "C:/Dev/compojure/deps/jetty-6.1.16.jar")
> (add-to-list 'swank-clojure-extra-classpaths
>              "C:/Dev/technomancy-clojure-http-client/src")
>
> etc... just add directories and jars as needed
>
> 2. Your .emacs file would be here: C:\Documents and Settings\${your
> username}\Application Data
>
> 3. I don't know about this one, but I had problems setting my home
> directory. Even though I did it, it was still looking in C:\Documents
> and Settings\${your username}\Application Data. Files there would load
> fine.
>
>
>
> On Wed, Jul 8, 2009 at 8:02 PM, Shawn Hoover<shawn.hoo...@gmail.com> wrote:

Shawn Hoover

unread,
Jul 8, 2009, 11:35:59 PM7/8/09
to clo...@googlegroups.com
On Wed, Jul 8, 2009 at 2:56 PM, Mani <dum...@gmail.com> wrote:

Thanks Shawn, Robert.
From Robert's post, I am bit confused here. I also read that .emacs is
in %appdata% folder (vista), but all I see is .emacs.d folder (which I
guess is for the emacs server). I tried creating one "C-x C-f
~/.emacs" - under my home-directory (C:\emacs). Should i just create
a .emacs under %appdata%/.emacs.d  OR right under %appdata%?

Wherever the files goes after C-x C-f ~/.emacs and then C-x C-s is where emacs thinks your home directory is. I would just go with that. It's normally in %appdata%, but it won't be there until you create it and save it.

For ideas for a .emacs from scratch, you can look at http://bitbucket.org/shoover/emacs/src/tip/init.el.

Shawn

Robert Campbell

unread,
Jul 8, 2009, 11:58:54 PM7/8/09
to clo...@googlegroups.com
> Wherever the files goes after C-x C-f ~/.emacs and then C-x C-s is where
> emacs thinks your home directory is. I would just go with that. It's
> normally in %appdata%, but it won't be there until you create it and save
> it.

yes, this is better than my #2

> Robert? Is that all you have in your .emacs? I am looking to create
> one from scratch.

Here is my entire .emacs file, which is extremely basic but got me up
and running at least:

--------------------------

(setq swank-clojure-extra-classpaths
'())
(add-to-list 'swank-clojure-extra-classpaths
"C:/Program Files/Clojure Box/clojure/clojure.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Program Files/Clojure
Box/clojure-contrib/target/clojure-contrib-1.0-SNAPSHOT.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Program Files/Clojure Box/compojure/deps/jetty-6.1.16.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Program Files/Clojure Box/compojure/deps/jetty-util-6.1.16.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Program Files/Clojure
Box/compojure/deps/servlet-api-2.5-20081211.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Program Files/Clojure Box/compojure/deps/commons-codec-1.3.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Program Files/Clojure
Box/compojure/deps/commons-fileupload-1.2.1.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Program Files/Clojure Box/compojure/deps/commons-io-1.4.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Program Files/Clojure Box/compojure/compojure.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Dev/user/libs/postgresql-8.3-604.jdbc4.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Dev/technomancy-clojure-http-client/src")

(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(cua-mode t nil (cua-base))
'(show-paren-mode t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)

--------------------------

You'll notice the paths are different (I changed it during my first
post) but obviously they aren't relevant. A big problem I had was
getting versions of Clojure, Contrib, Compojure, Enlive, HttpClient,
etc. that all play well with each other. I'd frequently have a version
of Compojure/Enlive/HttpClient that was dependent on one or another
Contrib version, etc. A quick trick I learned was to just check out
Compojure from git, run the ant deps which downloads the dependencies
compatible with that version, and just use those because James of
Compojure has done the work syncing them all up, so:

(add-to-list 'swank-clojure-extra-classpaths
"C:/Program Files/Clojure Box/compojure/compojure.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Program Files/Clojure Box/compojure/deps/clojure.jar")
(add-to-list 'swank-clojure-extra-classpaths
"C:/Program Files/Clojure Box/compojure/deps/clojure-contrib.jar")

But with 1.0 out now I haven't had as many issues.

Rob

Daniel

unread,
Jul 9, 2009, 1:35:06 AM7/9/09
to clo...@googlegroups.com
On Thu, Jul 9, 2009 at 1:56 AM, Mani<dum...@gmail.com> wrote:
>
> Thanks Shawn, Robert.
> From Robert's post, I am bit confused here. I also read that .emacs is
> in %appdata% folder (vista), but all I see is .emacs.d folder (which I
> guess is for the emacs server). I tried creating one "C-x C-f
> ~/.emacs" - under my home-directory (C:\emacs). Should i just create
> a .emacs under %appdata%/.emacs.d  OR right under %appdata%?
>

From the EmacsWiki [1]: "If the init file ~/.emacs does not exist,
Emacs will try ~/.emacs.d/init.el"

Since you usually have more than a couple of things that you want to
configure, emacs.d gives you a directory instead of a file for
configuration. That makes it easier to keep things organized. If you
put what you want into %appdata%/.emacs.d/init.el, you should be fine.

I guess ClojureBox is a good starting point for Emacs with Clojure. A
little bit more general is the Emacs starter kit [2] from Phil
Hagelberg (Clojure regular), and if nothing else, reading the readme
(displayed on the linked page) is recommended because it gives you a
bit of intro on Emacs configuration (ClojureBox might even use the
starter kit, but according to this [3] it doesn't. Didn't check
though).

Hope that helps

Cheers,
Daniel

[1] http://www.emacswiki.org/emacs/DotEmacsDotD
[2] http://github.com/technomancy/emacs-starter-kit/tree/master
[3] http://groups.google.com/group/clojure/browse_thread/thread/6fd17fb97f058192

cschep

unread,
Aug 11, 2009, 1:46:18 PM8/11/09
to Clojure
Hey all,

I recently went through this process as a total clojure/emacs noob.
Trying to use the command line (especially in Windows) to enter
samples that were more than one line was just brutal. Also, I really
wanted the emacs experience while toying around with Clojure samples
and reading this great book.

In case another total noob stumbles across this and needs help, this
is what I did from start to finish to get Clojure Box up and running
with the sample code for "Programming Clojure" by Stuart Halloway.
(trying to help out the googlers)

1. Install Clojure Box! This is very simple download here:
http://clojure.bighugh.com/
2. Download the book's sample code here: http://www.pragprog.com/titles/shcloj/source_code
(I went with the ZIP file)
3. Extract the archive to a place you can remember!
4. Run Clojure Box
5. Use the keyboard shortcut to fine a file: C-x C-f, then type
~/.emacs -> enter (this opens a file, even if it doesn't exist
already!)
6. I am assuming this will come up blank for most of you, if you have
already customized your emacs install, then you probably don't need
this HOWTO. So on your blank screen, add this:

(setq swank-clojure-extra-classpaths
(list "D:/home/mydrop~1/code/clojure/shcloj-code/code"))

your path should be the path to where you extracted your sample code!
This where is mine ended up. Mind the FORWARD slashes! That honestly
took me 30 minutes to figure out. Even in Windows, emacs likes the
FORWARD slashes.

I also added:

(tool-bar-mode -1)

to get rid of the pesky (ugly) graphical toolbar, but do what you
like.

7. *IMPORTANT* You must save this file! C-x C-s, you should see emacs
tell you where it wrote the file to at the bottom of the screen, mine
ended up in "C:/Documents and Settings/chris/Application Data/.emacs

8. Close emacs, then run it again. It will ask you about running
processes, because there is a clojure REPL running, totally fine to
kill it, you haven't done any work yet, right? When you open it back
up, it should look exactly the same as before...BUT! Head back to page
37 (ish) and read about requiring and using other pieces of clojure
code. At the REPL type:

=> (use 'examples.introduction)
nil <--- you should get nil as a response!

=> (take 10 fibs)
(0 1 1 2 3 5 8 13 21 34) <--- hooray it worked! We're running the
book's sample code!


9. Enjoy the rest of the book with an extremely powerful tool to help
mangle the code samples :)

This is as far as I've gotten in the book, so hopefully all the
versions line up correctly to work with the samples. If there is weird
breakage, I am sorry! As I continue to wade through the book I'll try
to update if I encounter anything weird and especially if I can find a
way to fix it.

Also, excuse this if it is redundant, but I was trying to get this to
work for a while last night and would have really found something like
this helpful.

happy Clojuring!


On Jul 8, 10:35 pm, Daniel <dan.in.a.bot...@gmail.com> wrote:
> [3]http://groups.google.com/group/clojure/browse_thread/thread/6fd17fb97...
Reply all
Reply to author
Forward
0 new messages