Hi guys : Im used to letting maven do all my dependency management in java (and lein in clojure). Thats the good news. The bad news is that I have a java app, and wanted to use it as a library in a clojure script.
What is the simple way to add (non Sun) java classes to a clojure application (without explicitly modifying the system classpath, of course) ?
I was wondering wether maybe I could just "jar" up my application and put it in the root directory of my clojure source code....... ?
Hmmm im thinking this might be a misunderstanding.
So there is no native support in clojure for importing jar files?
Well... I guess there is always runtime.exec
But that seems like overkill... Java supports dynamic class loading, so I would think there would be a "code" based way to load classes from a jar using standard Jdk+clojure without leinigan/maven ...?
I was launching "REPL" (still not quite sure why i need to launch a web-server to run a program) through a shell script, but then i got my hands on the eclipse plugin, which launches repl in a strange, somewhat counter-intuitive manner (albeit convenient) . . .
I dont have any one way of running clojure --- i basically want to know what the simplest, dependency free way to launch it will be. I want it to be 100% jar driven, and i dont wany to rely on other constructs....
Another interesting clojure question regarding forms :
I noticed that
let [[ x y z ] [1 2 3 4 5]]
somehow maps x y and z into 1 2 3....
How does clojure know how to do this ? Is it capable of inferring the similarity of the two data structures, and then intelligently guessing how i want to map them ? I always assumed that each var in a let statement would have to be a variable. For example
let [ x 1
y 2 ]
maps x to 1, and y to 2.
By that logic, let [ [x y z] ] should throw an "exception" (or compile error) since the first character is a "[" and not a var name ?
REPL - Read-Eval-Print-Loop - is not a web server, it's an interactive console, much like Ruby, Groovy and Scala all have. Which shell script were you using to launch it?
If you're launching the REPL in Eclipse, you can just add your JAR to your Build Path in Eclipse and then (import ...) your Java classes.
I strongly recommend Leiningen as your default build tool. It makes dealing with dependencies and packaging your application really simple - much simpler than any manual process you will come up with
Now, on to let:
That's called destructuring. You can destructure vectors and maps in a binding (and therefore in function arguments too).
Here's a more complex example to show you how powerful the matching and binding can be:
This shows map destructuring with a default (for c, because it's not in the map - the first element of the vector) as well as nested destructuring and the use of & to match the "rest" of a sequence - [f & g] is bound to [[5 6] 7] so f is bound to [5 6] and g is bound to the rest of the enclosing sequence: (rest [[5 6] 7]) is (7).
I spent the morning putting in a comma and the afternoon removing it.
-- Gustave Flaubert, French realist novelist (1821-1880)
Are we home yet? Wait, did we forget the tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop