Missing doc in non-user namespaces in Clojure 1.5 - clojure

What should I do to get doc available again?
brew install --devel leiningen
lein new app yeehaw
cd yeehaw
; edit project.clj and replace "1.4.0" with 1.5.0-RC1"
lein repl
yeehaw.core=> (doc map)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: doc
in this context, compiling:(NO_SOURCE_PATH:1:1)
This change comes from CLJ-1085 and this associated source.
Note that doc and the usual REPL functionality is still available in the user namespace, but it would be nice to have it at my fingertips in my app's namespace, at least while in the REPL.

Get doc into current namespace:
(clojure.core/use '[clojure.repl :only (doc)])
And after that try doc again.

Thanks to help from clojure IRC, here are some options:
use clojure.repl/doc instead of doc
use (apply require clojure.main/repl-requires) to bring doc and other REPL functionality into a new namespace.

Related

leiningen project: repl-options/init

When I add :repl-options {:init (print "x..")} to ~/.lein/profiles.clj it does what it should on every repl start-up. however, when I add the same to my local project.clj, I receive this error:
Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: do in this context, compiling:(/tmp/form-init5885833654225579206.clj:1:886)
I'm using leiningen 2.5.3
I've stumbled across this issue as well - I tried to use multiple profiles, each with its own :repl-options.
The issue is that Leiningen doesn't merge `:init: correctly. You can refer to this issue for more details.
Unfortunately, I couldn't find any fix that would work for me. And the issue itself won't be fixed till Leiningen 3.0.

Lein console (like sbt)

Is there some built-in functionality or plugin to lein to get a lein console, so for example one could test without waiting every time for JVM to start up.
$ lein console
>>> test
...
>>> test
...
>>> jar
Note: I'd like to trigger test runs myself, not e.g. by watching source files. That's why I'd like to have a lein console.
Clarification: I'm not looking for lein repl. I'd like to have a console where I could run lein task commands.
Older versions of leiningen used to include lein interactive, which behaved much like the feature you are asking for: it opened a shell into which you could type test and have it run lein test from the already-running lein jvm, and so on. This feature was removed in the transition to lein 2.0, I think, and although I don't know why I suspect there was a good reason. Maybe try asking in #leiningen on freenode?
You might want to have a look at grenchman. While it's not a Leiningen console it at least enables reusing of an existing REPL session. From what I gather, usage is as follows:
Move somewhere that is not inside a project and call:
$ lein repl :headless
Within your project directory, use:
$ grench lein <task> <options>
Tasks will be run inside the already spun up Leiningen JVM and the startup overhead should disappear.
Building grenchman seems to be tedious, though, and it is recommended to use one of the precompiled binaries (BUT they are currently not available).
And finally, that page also states:
Grenchman is still very new and may not be fully reliable.
So, good luck, I guess?
One option is to run a repl from leiningen's own jar file.
$ java -cp ~/.lein/self-installs/leiningen-2.5.0-standalone.jar clojure.main
Clojure 1.6.0
user=> (require '[leiningen.core.project :as project] '[leiningen.test :as test])
nil
user=> (def prj (project/read))
#'user/prj
user=> (test/test prj)
lein test org.noisesmith.orsos.load-test
Ran 3 tests containing 3 assertions.
0 failures, 0 errors.
nil
user=> (require '[leiningen.jar :as jar])
nil
user=> (jar/jar prj 'org.noisesmith.orsos)
Compiling org.noisesmith.orsos
Created /media/justin/806084F16084EEEA/clojure/orsos/target/orsos-0.1.0-SNAPSHOT.jar
{[:extension "jar"] "/media/justin/806084F16084EEEA/clojure/orsos/target/orsos-0.1.0-SNAPSHOT.jar"}
user=>
As a baseline, this can run lein tasks without having to restart lein every time. If you also use rlwrap or use nrepl it becomes a bit more usable. As far as I know there is no user friendly tooling around this (though there easily could be).
If you wish to use tasks from lein plugins those can be added to the -cp arg.

clojure namespaces .core file and repl

A beginners question.
running clojure using lein + emacs + nrepl.
I am slightly confused about the following:
I wish to use the exponent function. This function lives in the following place clojure.math.numeric-tower. I add [org.clojure/math.numeric-tower "0.0.1"] to the dependencies and run lein deps.
Now is it possible (I'm sure it is possible) to add this to my .core ns as follows:
(ns learning.core
(:require [clojure.math.numeric-tower :as math]))
(def i-know-the-answer
(math/expt 2 10))
now when I try to load (ctl-x e) this into the REPL, it throws errors.
clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: No such namespace: math, compiling:(NO_SOURCE_PATH:2)
do the dependencies need to be loaded into the REPL directly? Can I not just change the source file / recompile it and use that?
Load the file with ctrl-c ctrl-l then Switch your repl to the namespace in that file with either
(in-ns 'learning.core)
Or hit ctrl-c alt-n from the Clojure buffer to switch the repl to the buffer's namespace. You can tell if it worked by looking at the prompt in the repl.

Getting slime to find files on classpath, and contrib

I recently decided to start using Slime/Swank for writing Clojure. I installed Incanter, Clojure, Slime and Swank yesterday by following this blogpost to the letter, which worked fine. However, I'm experiencing a problem getting Slime to find directories and files on the classpath. I'm running Slime using lein swank and slime-connect in Aquamacs on OS X 10.6. I have two questions:
1) I set up a small project to build a game of life simulation. I have a file called grid.clj from doing this earlier, which I put in the project's lib directory. In core.clj I put the following
(ns gof.core
(:require grid))
(def w (grid.make_grid 8))
Doing C-x C-e after this piece of code gives this error message in the repl:
Could not locate grid__init.class or grid.clj on classpath:
[Thrown class java.io.FileNotFoundException]
so I looked at my classpath using
(doseq [p (.getURLs (java.lang.ClassLoader/getSystemClassLoader))] (println (.getPath p)))
which produced this:
/Users/zjanes/Documents/gof/test/
/Users/zjanes/Documents/gof/test-resources
/Users/zjanes/Documents/gof/src/
/Users/zjanes/Documents/gof/classes/
/Users/zjanes/Documents/gof/resources
/Users/zjanes/Documents/gof/lib/clojure-1.3.0.jar
/Users/zjanes/Documents/gof/lib/grid.clj
/Users/zjanes/.lein/plugins/swank-clojure-1.3.4.jar
nil
user>
It seems to me that grid.clj is on this classpath, so why am I getting the error message?
2) In trying to solve this I had a look at clojure-1.3.0.jar and couldn't find anything that looks like it comes from clojure.contrib. Is contrib not included when installing clojure as described above?
I'm sure it's obvious I'm a complete novice with clojure, so the clearer the answer, and the less presumed knowledge, the better.
For completeness, I've looked at these answers (1 2 3) and this page, plus some googling around.
Thanks in advance
that tutorial is from 2009 and as far as I can tell it can't be made to work using those instructions.
Clojure contrib has been split up into many sub projects in clojure 1.3 so it no longer exits under that name.
in general clojure namespaces now have two parts, for instance:
(ns gof.core
(:require [incanter.grid])

clojure.contrib.duck-streams FileNotFoundException, why?

user=> (use '[clojure.contrib.duck-streams])
java.io.FileNotFoundException: Could not locate clojure/contrib/duck_streams__in
it.class or clojure/contrib/duck_streams.clj on classpath: (NO_SOURCE_FILE:0)
Clojure.contrib is in CLASSPATH still it is throwing Exception. Do I need some other Jar?
Use clojure.java.io instead, it's included with 1.2.
I highly recommend using leiningen to sort this out.
try the lein repl command to get a quick repl with a working classpath.
According to this message:
http://osdir.com/ml/clojure/2010-10/msg00834.html
clojure.contrib.duck-streams has been deprecated.