5 ms·
$ lein new myproj Created new project in: myproj $ cd myproj $ lein deps [copy] Copying 2 files to myproj/lib $ lein repl Clojure 1.1.0
by gcv 16y ago
$ lein new myproj
Created new project in: myproj
$ cd myproj
$ lein deps
[copy] Copying 2 files to myproj/lib
$ lein repl
Clojure 1.1.0
user=> (use 'clojure.contrib.json.read 'clojure.contrib.json.write)
nil
user=> (read-json (json-str {"1" "2"}))
{"1" "2"}
I admit I cheated a bit: clojure-contrib comes with a JSON parser, and lein automatically includes a dependency on clojure-contrib. If I needed a different library, I'd have edited project.clj to include the dependency.
- technomancy 16y agoThe main difference is that you can modify your $LOAD_PATH at runtime in Ruby, while on the JVM it's fixed at startup. This is particularly ironic because it's a cultural norm in the Ruby community to launch lots and lots of short-lived ruby processes to run your tests, while in Lisp-land it's much more common to have very long-running repl sessions with uptimes often lasting in the days range.
- weavejester 16y agoYou could put a temporary directory on your class path, and then unzip any jars into it. You could then reload Clojure source files, although I'm not sure if you'd be able to do anything about Java class files without a custom class loader.
- thangalin 16y agoThe CLASSPATH can be modified at runtime by writing custom class loaders. It isn't trivial, but it is possible. I had to do it to implement Hierarchy: http://www.whitemagicsoftware.com/software/java/hierarchy/ http://www.whitemagicsoftware.com/software/java/hierarchy/
- jshen 16y agoYou cheated in two ways. Ruby Gems comes with every version of ruby I've ever used. If I go to the clojure site where does it mention lein? How do I add another lib? Here's the ruby site on this topic, which is linked from the top of almost every page on the site. http://www.ruby-lang.org/en/libraries/ http://www.ruby-lang.org/en/libraries/ It's amazing that you get voted up when you are clearly avoiding my point. Show an example without cheating! What if I wanted to talk to mysql instead of using json. My ruby example would be the same. gem instal ...; irb; require; use it
- timclark 16y agoWhen Ruby was the same age as Clojure I don't think it was as easy as using RubyGems - the first time I became aware of RubyGems was when this new fangled Rails thing started!
- gcv 16y agoHow do I add another lib? ... Show an example without cheating! It's amazing that you get voted up when you clearly did not read my post. I wrote: "If I needed a different library, I'd have edited project.clj to include the dependency." Let me explain that in detail: lein generates the following default project.clj: (defproject myproj "1.0.0-SNAPSHOT" :dependencies [[org.clojure/clojure "1.1.0"] [org.clojure/clojure-contrib "1.1.0"]]) Then you change it to: (defproject myproj "1.0.0-SNAPSHOT" :dependencies [[org.clojure/clojure "1.1.0"] [org.clojure/clojure-contrib "1.1.0"] [mysql/mysql-connector-java "5.1.13"]]) To wit: you add a dependency by including it in the :dependencies vector. For example, Berkeley DB JE would be [com.sleepycat/je "4.0.92"]. Then you run "lein deps", which takes care of the rest. I hope you aren't arguing that editing a text file to include a dependency is too difficult, so I'll address your other point: the Clojure site does not mention Leiningen. There's actually a good reason for it: it is not a core necessity for using the language; you don't have to use Leiningen to use Clojure. If you understand the classpath, you don't really need it. Leiningen is a convenience, not a necessity of life. I'll readily agree that an overview of available development aids would make for a nice addition to clojure.org. No definitive "Beginner's Guide to Programming in Clojure" exists. It would ideally explain how to get started at the REPL, how to use SLIME and swank-clojure to work with Emacs, and how to use VimClojure to work with vi, how to handle packaging, and how to deal with dependencies. It would also explain why and how someone might want to use Ant, Maven, Ivy, Leiningen, and the clojars.org repository. I'm sure that someone will write this guide some day soon.
- jshen 16y agoThis still assumes a lot. It assumes the lib is in a maven rep, it assumes use of lien which isn't standard like gems at this point, and let's be honest, maven is a beast compared to gems. You said that clojure is as easy as ruby for a noob. The simple fact is that it isn't, and you've essentially admitted as much.