How to fix backtrace in clojure & slime - clojure

I'm a clojure noob trying to get emacs & slime set up. There doesn't seem to be one true way to do this, so I've followed a few blog posts and the swank-clojure and leiningen READMEs.
Mostly it works. My problem is that if I try to select restart 0 [QUIT] from a backtrace, I get
'error in process filter: Wrong number of arguments: nil, 0'
(I also see a warning on 'M-x slime-connect' about slime and swank being mismatched versions, but Googling suggests this is expected).
This is Debian Lenny. I got slime via 'git clone git://git.boinkor.net/slime.git'.
Clojure and clojure-contrib are 1.2.0, and swank-clojure is 1.2.1.
Anyone seen this? Alternatively, is there an up-to-date list of compatible versions of all the pieces? Many thanks.
Edit:
Looks like it is probably this issue. I followed the same blog post as the OP in that thread.
Edit:
Yes. Getting slime and slime-repl packages using ELPA fixed it.

Don't get slime via git, but use ELPA. See the links in my edits to the question.

the clojure ecosystem has changed a lot over this last year so many of the most linked tutorials sort of do things the hard way. you dont really need to build clojure/contrib and install it anymore. both Maven2 and leinengen do this ver well for you.
you may be able to get up and clojureing just by installing lein (from the tutorial) and then making a new project. this is enough to keep me happy even on my larger projects. you dont really need to install clojure system wide.
from a (ubuntu-10.10) system that has never seen clojure before i run:
dev:~$ lein new foo
Created new project in: foo
dev:~$ cd foo
dev:~/foo$ ls
project.clj README src test
dev:~/foo$ lein repl
Downloading: org/clojure/clojure/1.2.0/clojure-1.2.0.pom from central
Downloading: org/clojure/clojure-contrib/1.2.0/clojure-contrib-1.2.0.pom from central
Downloading: org/clojure/clojure-contrib/1.2.0/clojure-contrib-1.2.0.pom from clojure
Transferring 4K from clojure
Downloading: org/clojure/clojure/1.2.0/clojure-1.2.0.jar from central
Downloading: org/clojure/clojure-contrib/1.2.0/clojure-contrib-1.2.0.jar from central
Downloading: org/clojure/clojure-contrib/1.2.0/clojure-contrib-1.2.0.jar from clojure
Transferring 466K from clojure
Copying 2 files to /home/arthur/foo/lib
"REPL started; server listening on localhost:20092."
user=> (+ 1 2 3)
and thats all you really need. have fun :) (of course there is a LOT more to the clojure ecosystem though there is no need to really rush into it)
ps: add swank-clojure as a dev dependency and run lein swank and then slime-connect from within emacs
ps: I hit 'q' to exit the backtraces.

Here's an update for google: things have changed since the previous answers and the correct way to start swank/slime is now via the clojure-jack-in command in recent versions of clojure-mode, which uses the corresponding lein jack-in command in recent versions of swank-clojure. Using clojure-jack-in, all the Emacs dependencies other than clojure-mode are automatically installed for you. DO NOT install slime.el or slime-repl.el manually, via ELPA or via git.

Related

How to load this Clojure project in my cider REPL? Why I am receiving the message "The clojure executable isn’t on your ‘exec-path’" (NixOS)?

Recently, I started learning Clojure. I have been using Emacs, and cider (REPL). Also, I have NixOS as OS.
I have been able to successfully program in Clojure using this environment. Usually, I create the files, then I go to the directory where the .clj are, I execute cider-jack-in, a REPL is created, and interactive programming magic happens. Thus, I am able to load the file, load new versions of old functions, etc.
It also works if I just start Emacs and execute `cider-jack-in. The mini-buffer asks:
Are you sure you want to run `cider-jack-in' without a Clojure project? (y or n)
After answering y, everything works fine.
While reading the book Clojure for the Brave and True, I have also successfully used:
$ lein run
For learning purposes, I decided to explore some open source projects. Thus, I did a git clone of this open-source project.
Being on the folder, I decided to reproduce the steps that have worked so far. However, it does not work. After executing cider-jack-in, the mini-buffer echoes the following:
The clojure executable isn’t on your ‘exec-path
Also, if I try with lein I get:
[pedro#system:~/projects/http-cron]$ lein run
No :main namespace specified in project.clj.
Obs.: If I type clojure on the shell, this is what I get:
[pedro#system:~]$ clojure
The program 'clojure' is not in your PATH. You can make it available in an
ephemeral shell by typing:
nix-shell -p clojure
Why is this happening?
How can I solve this (considering that I am using NixOS)?
Going the imperative route, depending on whether you use NixOS with channels (default) or flakes, you can permanently install clojure into your environment with:
channels: nix-env -f '<nixpkgs>' -iA clojure
flakes: nix profile install nixpkgs#clojure
The preferred (declarative) way would however be adding clojure to environment.systemPackages in /etc/nixos/configuration.nix and running sudo nixos-rebuild switch.

Unable to get `cider-jack-in` to work

See an error message: error in process sentinel: Could not start nREPL server: That’s not a task. Use "lein help" to list all tasks.
In the *Messages* buffer, the full form of the error is:
error in process sentinel: nrepl-server-sentinel: Could not start nREPL server: That’s not a task. Use "lein help" to list all tasks.
M-x cider-version shows
CIDER 0.15.0snapshot (package: 20170525.255)
Tried fiddling around with ~/.lein/profiles.clj to explicitly add in
{:user {:plugins [[cider/cider-nrepl "0.15.0snapshot"]]}}`
... but that didn't change anything.
(getting back to Clojure after a while with a "fresh" install (Emacs, clojure-mode, cider, etc. so might have missed some small environment setup step, just don't know what that is!)
Turns out the incompatibility was not with the nRepl middleware, but with Leiningen itself.
Once I uninstalled the version I had installed using apt-get, and self-installed using the downloaded script, and made sure this new version was what which lein led to, this problem went away.
More details: Running cider-jack-in was triggering a call to lein update-in with further arguments, but the version of Leiningen I had simply didn't show update-in as one of the options when I ran lein help.

ClojureScript bRepl does not respond at all

I've been tinkering with clojure and clojurescript for some time and I always found the browser repl to be extremely unresponsive. It usually hangs on without giving a result, or throws a broken pipe exception. Now I'm in a situation where it always refuses to work.
Let's say I download the modern-cljs tutorial part 2 and I do all the steps to start the page, load the compiled javascript and start the bRepl. When I try to evaluate something as simple as (+ 3 4) well, it just doesn't work.
I'm on OSX 10.8.4 and my leiningen version is 2.3.2 on Java 1.6.0_51 Java HotSpot(TM) 64-Bit Server VM. Any help is extremely appreciated.
I would suggest to clone the modern-cljs repo, then checkout the tutorial-02 branch, then clean and recompile.
git clone https://github.com/magomimmo/modern-cljs.git
cd modern-cljs
git checkout tutorial-02
lein do clean, cljsbuild clean
lein cljsbuild once
Be sure to have your http-server running (I'm assuming the port is 3000) and its root set to modern-cljs/resources/public directory
Then run the repl-listen substask as follows:
lein trampoline cljsbuild repl-listen
Wait for the cljs prompt. Then visit the localhost:3000/simple.html URL and wait that the connection with the brepl is ready.
At the cljs prompt you should now be able to evaluate cljs expressions. Eventually, reload the above URL.
If it still does not work, try to delete your maven repository:
rm -rf ~/.m2/repository
and redo everything from the lein do chain of commands.
Eventually you can follow the https://github.com/magomimmo/modern-cljs/blob/master/doc/tutorial-18.md#the-need-of-a-more-comfortable-brepl-experience tutorial to set up a more comfortable bREPL which uses https://github.com/cemerick/piggieback
HIH
I've had a few problems with this topic too. And here are the tricks that help me:
Clean leain deps: rm -rf ~/.m2/*
download lein deps: lein deps in your project root
I saw this message: "broken pipe" when there was too much time from the last brepl interaction. So, refresh the browser and that's all
sometimes my brepl hung on the first time i was trying to evaluate the code, again try to refresh the browser
don't forget to run: lein cljsbuild once before start the brepl
Good luck
PS: Anyway if you want to have a comfortable brepl experience you have to take a look to https://github.com/cemerick/austin . I have tested this brepl and works fine https://github.com/juanantonioruz/client
You should try using Chromium unsafely:
OS X:
open -a Chromium --args --disable-web-security
Linux:
chromium --disable-web-security
Then visit your page in the unsafe browser and try to connect to the brepl.
Explanation:
Because while brepl is running on port 9000, the web server hosting the page is necessarily using a different port, which constitutes XSS (see [this stack overflow discussion]).
The easiest way to get around this is to use Chromium unsafely for debugging, but you can enable XSS by some other means if you want.
What ClojureScript release are you specifying in your project.clj? If you aren't specifying a specific release, this likely the source of your troubles. 0.0-1913 is the latest one.
I've also seen a complete hang in the REPL when I forget to call repl/connect from within the browser. Since there is no output, it's hard to diagnose. It's worth verifying before you try more intrusive remedies.

Clojure : 'lein repl' history grepping?

I often find myself executing commands like this at bash :
history | grep 'find'
For example to look up a fancy find / xargs command i might have ran.
Im wondering --- where does the "lein repl" store its historical data ? It would be nice to know, because then I could write a leingrep.sh script, which simply grepped through the lein history session.
It is obvious that this is on disk somewhere, since history is preserved from one repl to the next.
Lein is using either readline (if you have it installed) or jline (if you are so unfortunate, I recommend installing readline). I wouldn't bother trying to look up the history file on disk - just press Ctrl-r, type in your search text, and keep hitting Ctrl-r until you find whatever you were looking for. This is a general readline feature, and will work in any readline app (including bash).
Once you get going with readline there are a couple controls to consider, via your ~/.inputrc file.
I'm not finding the default "history size" documented, but I'm guessing it's only ~100. I often lose some older entries I wished I'd had around. Also, "vi-mode" is wonderful thing for vi users. Together these (with a bonus) in .inputrc become:
set history-size 10000
set editing-mode vi
# Only require 1 tab for completion.
set show-all-if-ambiguous on
Note that this config will affect a lot of repl tools, like gdb, irb/pry, lein, psql, ipython, R, ...
Looking at my home folder. Seems like the lein repl has chosen jline.
The files where the history is stored is as follows:
~/.jline-clojure.main.history
~/.jline-reply.history
Hope this helps.
I installed lein through Homebrew on my Mac:
brew install leiningen
and the history file is stored in my home directory:
~/.lein/repl-history
Version is:
% lein --version
Leiningen 2.6.1 on Java 1.8.0_77 Java HotSpot(TM) 64-Bit Server VM
(I don't have no ~/.inputrc nor ~/.jline*)

Is Clojure installable this way?

I downloaded Clojure 1.2 https://github.com/downloads/clojure/clojure/clojure-1.2.0.zip , extracted it under /Library directory, created CLOJURE_HOME, added $CLOJURE_HOME/script to my $PATH.
When I'm trying to run clj or repl scripts that are located under script directory, I'm getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: jline/
ConsoleRunner
Caused by: java.lang.ClassNotFoundException: jline.ConsoleRunner
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Ok, jline.jar isn't in the CLASSPATH so I checked clj and repl scripts:
CLASSPATH=src/clj:test:test-classes:classes/:script/jline-0.9.94.jar:../clojure-contrib/target/clojure-contrib-1.2.0-SNAPSHOT.jar
if [ -z "$1" ]; then
exec java -server jline.ConsoleRunner clojure.main
else
SCRIPT=$(dirname $1)
export CLASSPATH=$SCRIPT/*:$SCRIPT:$CLASSPATH
exec java -Xmx3G -server clojure.main "$1" "$#"
fi
I downloaded jline.jar under $CLOJURE_HOME/script but I'm still getting the same error.
This lead me to the question:
What is the role of https://github.com/downloads/clojure/clojure/clojure-1.2.0.zip anyway?
Is it supposed to be used to install Clojure? or just to to build and get clojure.jar?
I noticed no one is talking about installing Clojure this way.
Am I missing something?
Clojure, being a JVM language, has to deal with the JVM classpath. This makes 'installing' it a bit unwieldy and confusing. Rather than install it yourself like this, try out some tools like cljr and cake. I wrote a blog post about this that might be helpful: http://blog.raynes.me/?p=48
In summary: Check out cljr, cake, and leiningen.
The majority of people in the Clojure community don't have Clojure 'installed'. Most people use a build tool and/or cljr. It doesn't make a lot of sense to install Clojure to a central place when, inevitably, you're going to need dependency management, and jars will be copied around everywhere anyway. In any case, it's much easier to let a tool handle the classpath for you.
the clojure.zip file exists so people who write tools will have a place for their tools to get the parts they need ;)
For people not writing tools they are either working on/with the latest branch from github and so they get Clojure with a git pull or they are using the above mentioned liningen, cake, cljr , counterclockwise(eclipse), la clojure (intellij), or netbeans.