Robert,

On Jul 8, 2009, at 2:13 AM, Robert Campbell wrote:

> Sometimes I have pretty long REPL sessions where I'm trying to flesh
> out some ideas. When I close my instance of Clojure Box (Emacs based)
> I lose all the definitions I had worked out over time. Is there any
> way to dump namespace(s) to an image? It would be great to be able to
> load up some workspace image and pick up where I left off.

Something similar was discussed recently but didn't come to a solid  
conclusion: 
http://groups.google.com/group/clojure/browse_thread/thread/4efaee2e67a272c6/f24578bfa06e6b9c?lnk=gst&q=printing+and+reading+a+function#f24578bfa06e6b9c

This is kind of a cop-out, but in general my advice would be to work  
from a file. Get your Clojure and Emacs set up so that you can compile  
your stuff pretty easily and your files are in the namespace- 
appropriate folder underneath your classpath. For example, I keep my  
Clojure code in ~/Projects/Languages/Clojure and my Emacs config looks  
like this:

(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"))

Now if I want to load or compile a Clojure file, it just works.

Next, when I start doodling I make a file in the aforementioned  
directory and put my stuff in there and open up a slime session in  
another window. C-c C-c sends the current form over Slime to the  
running session. Then I do my interactive testing and exploration in  
the slime session. Whenever I hit on a form I want to keep, I copy and  
paste it over to the file and make it into a function over there. I  
might make a function with a dumb name like demo or test and put a  
bunch of forms in there, and eventually they get refactored into unit  
tests (or not). If I close Emacs and reopen it on a file that doesn't  
yet have a namespace and whatnot, I select the stuff I want to  
evaluate and do C-c C-r to evaluate the region. It's handy, if less  
transparent.

The main advantage to this, apart from keeping the code clean, is that  
you avoid the dirty image problem that can happen with Common Lisp or  
(I assume) Smalltalk, where the code seems to work but accidentally  
depends on cruft in the image that never made it into the source file.  
I've had this happen in CL and found it very frustrating. I had a  
tumblog which I tried to make faster by saving images and found one  
day to my surprise that I couldn't make a fresh image on my server,  
which was running a different architecture, because the only reason it  
was able to make images on my box was because the first image had some  
crap in it that never made it to the source file. Maybe this problem  
isn't as prevalent in Smalltalk; maybe the JVM can circumvent this by  
being cross-platform, but it's happened more than once in CL. IIRC,  
CMU CL for a long time was self-hosting to such a degree it couldn't  
be built at all without a running binary of a previous version. That  
kind of thing makes porting to new architectures quite difficult.

Just my $0.02,

—
Daniel Lyons


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to