On Thu, Aug 25, 2011 at 11:19 PM, Lee Spector <lspec...@hampshire.edu> wrote: > > On Aug 25, 2011, at 9:27 PM, Ken Wesson wrote: > >> On Thu, Aug 25, 2011 at 6:49 PM, Lee Spector <lspec...@hampshire.edu> wrote: >>> While slurp and spit are beautifully elegant it's not so elegant to tell >>> slurp how to find the file you want it to slurp. In many other >>> languages/environments there's a concept of the working directory or >>> project directory, relative to which you can specify locations. In Clojure >>> you have to deal with the classpath, outside of the language proper, and >>> many of the common ways of running Clojure programs handle this >>> differently. I don't know if there's a good, general solution to this, but >>> for me (both as a programmer and especially as a teacher) it is definitely >>> a pain point. >> >> What about (System/getProperty "user.dir")? > > The value of user.dir depends on how the code is run. Now that I check I see > that if I run a lein repl in a project directory then it is set to that > directory, which is great. But if I run the code in some other way it may be > set to something different. For example, in clooj currently it's set to my > Downloads directory. I'll write to the clooj list to see if this can be > changed, but I also had problems with this sort of thing in > Eclipse/Counterclockwise and I'm wondering: Is it specified somewhere that > this should always be set to the project directory? If I run a lein repl from > a non-project directory then it's set to my home directory, which makes some > sense I guess, but why not the directory from which the repl was launched? > > FWIW my larger point was just that all of this is less clear than it is in > many other languages, and that simple file I/O is therefore less simple than > one might hope.
"user.dir" is the directory from which the JVM was launched, i.e. the initial working directory of the process. So, you're probably double-clicking the Clooj jar which resides in your Downloads folder and thus all further file system operations will be relative to that. For whatever reason it was decided long ago that the JVM wouldn't support the ability to change the current working directory like in most other environments. When you're working on a pure GUI app or server app, it usually doesn't matter, but when you've got a REPL it becomes a bit of a headache. Maybe someone could write a startup script for Clooj that first cds to the project folder before running "java -jar clooj.jar"? Alternatively, Clooj could maintain it's own working directory and override all the file-related ops (maybe??), but that will almost certainly lead to confusion as soon as someone uses a raw (FileInputStream.) and finds that the working directory isn't what they expected. Dave -- 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