I occasionally get this problem, and generally work around it, but it's rather frustrating.
I have all of Incanter (check it out if you don't know it: it's superb) on my classpath. I try to import it (through a Slime REPL) like this: user> (use 'incanter.core), but fail.
Doing this: user> (use 'clojure.contrib.def) works just fine, and this file is in the same place–on my classpath.
Regardless, the error isn't anything about classpath: it's this:
Don't know how to create ISeq from: clojure.lang.Symbol
[Thrown class java.lang.IllegalArgumentException]
You can see my entire terminal here (a screenshot.)
I don't know what's going on here, and it's really frustrating, as I really would like to use Incancter, and I can from the Incanter binary's REPL. I definitely don't want to develop from that–and this should work.
Any help would be much appreciated.
EDIT:
It appears as though Incanter requires Clojure 1.2, and lein swank gives me Clojure 1.1. This might be the cause of my problems: if so, is there a way to continue to use Swank & Lein with Clojure 1.2?
Thanks again!
EDIT:
Apparently if you start using Clojure-1.1 and lein swank, you're stuck with it unless you make a new project.
If future people have this problem, this article helped me out, but also, at least for me, you must start a new lein project if you had begun it using leink swank and Clojure-1.1. Simply changing your project.clj file and then lein swanking again doesn't work.
Yes, you can use Leiningen and swank-clojure with Clojure 1.2. You might need to use a recent version of Leiningen (I'm not sure if a certain old limitation affected lein repl only or was it lein swank as well; anyway, try the 1.2-RC2 which you'll find in the downloads section on GitHub). You will also need to use a recent-enough swank-clojure; I use a bleeding edge checkout myself, get yours here.
Other than that, simply use 1.2 jars for Clojure and contrib. (Lein uses it's own Clojure, separate from the one used for lein swank, for its internal workings and you never need to care about it; swank-clojure has no AOT'd namespaces and doesn't particularly care about the Clojure version, except once in a (long!) while something breaks, a patch is applied and joy is restored.)
I hope the above helps, but if it doesn't: your problem description is not entirely sufficient for me to get a clear picture of what is happening. Could you add information on what it means for "all of Incanter" to be on your classpath (do you mean the jars? sources? where do you get them? how do you set your classpath?). Without knowing this, it'll be hard to replicate your setup to try to track down the source of the problem.
Of course if bumping some versions fixes things, please disregard my current confusion. ;-)
Related
I'm having trouble understanding how to go from installing to using a cljsjs package. I am using the standard figwheel template, and I've made a little progress learning it, but now I'd like to use some 3rd party JS, and while cljsjs looks like the ticket, I can't find a clear example of how to actually use the packages.
I'm attempting to use the material package, to start with (http://material-ui.com). I'd like to just display a simple button to start.
I've added the [cljsjs/material "1.0.4-0"] to my project.clj, and lein installs it....now what?
Where and when should I (:require [cljsjs.material]) ?
How would I then create a <FlatButton> component, or whatever?
I see a resources/public/js/compiled/out/material.inc.js with what appears to be the full source for material - how do I use it?
Thanks in advance to any kind soul taking pity on a cljs beginner. It is incredibly appreciated. If there is anything out there that answers my question that my googling somehow missed, I apologize in advance.
The package [cljsjs/material] you're referencing does NOT use http://material-ui.com/ but instead uses: http://www.getmdl.io/
So there is NO <FlatButton>.
A primer on actually using cljsjs packages can be found here:
https://github.com/cljsjs/packages/wiki/Using-Packages
To use the material-ui package for example:
Put [cljsjs/material-ui "3.9.1-0"] in the :dependencies section of your project.clj file (make sure you update the version number to latest).
Require the cljsjs package in the (ns) section of your code: (:require material-ui)
Finally, you can reference the imported JavaScript objects directly by name: js/MaterialUI
It is sometimes difficult to figure out the JavaScript names. Generally you need to refer to the original JS package.
In the case of material-ui specifically, there are :global-exports helper mappings which you can see here, and these allow you to reference the library more conveniently and directly with material-ui.
Note that it is also quite often possible to import npm modules directly now with :npm-deps.
I am using the autoreload-server example which is working great for reloading namespaces on changes to the .clj files using ns-tracker.
https://github.com/pedestal/samples/blob/master/auto-reload-server/dev/dev.clj
However, it is not picking up changes to enlive templates in the resources/public dir. I've added my template paths to the vector in defn watch:
`([] (watch ["src" "resources" "resources/public" "public"]))`
As well as this in the namespaces that use enlive deftemplate:
(net.cgrand.reload/auto-reload *ns*)
However this does not work. My assumption is ns-tracker only works for clj files, and that I am using the enlive reload feature incorrectly.
Is anyone using enlive and have this figured out, or have any ideas to try?
I was hoping that Enlive Issue #6: Auto-reloading of templates was solved in early December 2013 in version 1.1.5 by this commit. But, in my testing, I cannot confirm that it is a fix. I might be doing something wrong.
A note: the example you cite, I think, dates from the pre-0.2.0 tooling changes for Pedestal. I could be wrong, but I think you'd be better off following the current documentation, not that sample file.
Pedestal's 'hello world' service app's key suggestions (which may change) are:
Use ns-tracker to figure out which namespaces to reload.
add :resource-paths ["config", "resources"] to project.clj so that Enlive can find your static HTML resources.
These steps are not enough to cause a change to a resource to trigger a reload, because ns-tracker will not pay attention to :resource-paths. Here are the details:
ns-tracker relies on clojure.tools.namespace.find/find-clojure-sources-in-dir.
clojure.tools.namespace.find/find-clojure-sources-in-dir
When you think about it, you can see why ns-tracker doesn't pick up resources; they aren't Clojure namespaces. In my opinion, this is coherent design decision, given the name, ns-tracker.
Still, pragmatically, it is clear that from the point of view of Pedestal that we do want to reload when a resource changes.
Now, let me add another thing. From a tooling perspective, let's say you do setup a watch on the resources directory. Even so, it is not easy to identify, in a granular fashion, which specific Clojure namespaces will be impacted. One resource may be used as a defsnippet by multiple deftemplate's. Therefore, one resource change can affect multiple Clojure namespaces. Strings pointing to resources might even be constructed dynamically. So, figuring out the exact minimal set of namespaces to reload may be impossible in the general case.
All of this said, it should be 'easy' and safe enough to reload all Clojure namespaces whenever a resource changes.
So, in summary, I have not solved this problem myself, but hopefully what I've explained above will help move the ball forward.
I could not find a working solution off the shelf, so I ended up writing a small ring wrapper that does the job, see https://github.com/kolov/enlive-reload
I have been learning Clojure a bit recently. Is there such a thing in Clojure world as Scala-like worksheets, into which I can put any code and get it evaluated as soon as I save it? Or maybe there's a similar solution for Clojure?
I am now working with lein repl and, sadly, can't say it's the most usable tool ever.
In Lisp development in general (and Clojure in particular) the preferred programming style is what's usually dubbed interactive programming - the developer keeps an image of the app loaded at all times and interacts with it via a REPL. You can easily modify the loaded code on the fly and test changes immediately in the REPL (that's not easy at all with Scala - one has to resort to something like JRebel to do it). I find the Scala worksheets a pretty primitive solution in comparison...
The workflow that I follow in Clojure is:
I open nREPL.el in Emacs - this loads my lein2 project with all of its dependencies and gives me a REPL which I can use the try out stuff
I write some code in source code and load the changed functions (maybe by evaluating a top level form with C-M-x
Afterwards I'd press C-x C-z to jump back to the REPL and I try out the new code in it
I go back to step 2
Basically the Clojure REPL is much more powerful than the Scala REPL and I personally consider it hugely superior to the Scala IDE worksheets. Once you get used to the interactive incremental style of programming Lisp offers everything else starts to look strangely complex by comparison. I'm not familiar with Eclipse's CounterClockWise Clojure plugin, but I'm pretty sure it offers similar functionality to Emacs's nREPL.el.
You might want to take a look at the autoexpect plugin for Leiningen. Every time you save any file in the working directory, the plugin compiles and runs your code; as a bonus, it will evaluate any "expect" function calls which can serve as tests. This is very helpful for test driven development and is a nice compliment to working with the REPL as described in the other answer (I often use one or the other or both together depending on how many test cases I have in place).
I should note that running autoexpect is far faster than running "lein test" or "lein run" repeatedly, due to the startup cost of the JVM and Leiningen.
It sounds like what you are looking for is the Clojure Koan plugin. This a worksheet-style problem-solving exercise tool that watches your edits and provides instant feedback on the correctness of your work.
For actual development workflow I second the advice others here have provided on tooling and interactive environment setup, but since you specifically said you are learning Clojure, this can be a fun approach. There is also a web application called 4Clojure that you might have fun playing with.
However you will eventually (or right away) want to get a smooth and convenient development environment set up, and I haven't seen any mention so far of a few important tools. One person mentioned Nrepl. If you like Emacs, there's a slime/swank-like interaction mode that jacks into nrepl called nrepl.el that provides very nice integration between editing files and messing around in the repl. Similarly there is VimClojure, and you can find plugins for IntelliJ (LaClojure) and Eclipse (Counterclockwise) that are also popular and well-maintained.
Someone mentioned autoexpect. If you are looking for a good TDD setup, I would recommend midje. If you are using a 2.0 preview release of leiningen there are a few issues with the lazytest integration being in flux, and lazytest itself is or should be deprecated. But I prefer midje over expectations, personally, and these problems will surely be worked out in the 2.0 release of lein-midje. The stable version of lein-midje that works with the non-preview (1.x) leiningen has autotest-like functionality using lazytest.
As nobody has mentioned it, cursive is really nice these days, although I was sad to move back to a full blown IDE. You can easily do the same thing as Emacs with the built in repl, just move into the namespace that you are working with and synchronise every time you make changes. It's a really nice way of working.
In my clojurescript code I have the following:
(defn onload [] (repl/connect "http://localhost:9000/repl"))
(set! (.-onload js/window) onload)
The Clojurescript repl is very useful in development, but I am hesitant to leave it in the code during production. What is the cleanest way to have the above code present during development (simple compilation), but absent during production (advanced compilation)?
The modern-cljs tutorial actually describes exactly how to solve this here.
Hope that helps!
Unfortunately there aren't currently any well defined ways to do conditional compilation in ClojureScript.
You could add configuration variables to control whether to start a REPL in a variety of ways, but one quick and easy way would be to get the hostname of the current page, and only invoke repl/connnect if it was "localhost" or whatever other domains you're using for development work.
I think a combination of lein2 profiles and cljsbuild src-paths munging can do the trick. eg, create a namespace that simply loads your repl, and exclude it with a profile run for the final compile (possibly might need to create a dummy namespace in another src-path directory).
I was wondering what autotest tools exists for clojure. In Ruby I have ZenTest, redgreeen etc to continuously keep on testing my code. I would like to have something similar for Clojure
So far I have found this simple script https://github.com/devn/clojure-autotest on the github. A bit crude for my taste. All tests run when a change occurrs. Also it may blurt out a long stacktrace in case of syntax errors, obscuring what goes wrong.
Take a look at the Testing section on the Leiningen plugin page.
Notably there's lein-autotest for Stuart Sierras lazytest framework and speclj.
If you are using clojure.test there are a few options available. lein-test-refresh is what I use (I'm also the author). Other options include quickie and prism.
If you use expectations then there is lein-autoexpect. I'm also the author of that.
Midje has built in support for autotesting. I'm not sure what the options are for Speclj.