This page introduces a lot of clojure libraries. And this page also comments to consider using the clojure-contrib.
Why the clojure-contrib.jar is different in size? The leiningen's clojure-contrib-1.2.0-beta1.jar is 479.2KB in size, but the conjure-contrib.jar that I downloaded from Programming Clojure is 2.9MB. As I explained in here. Does the clojure-contrib.jar is not standardized as of today?
Should the libs in the page be a part of clojure-contrib? If so, why leiningen's clojure-contrib.jar doesn't have the str-utils or repl-utils? As a result, I can't run (use 'clojure.contrib.str-utils) with leiningen (lein swank) in emacs/slime.
What's the meaning of clojure.contrib.A as is shown in the page? As far as I know, (use 'a.b) lets clojure to find CLASSPATH/A/B.clj to load and do refer as is explained in Programming Clojure book page 18. Is this saying that the A clj file in /clojure/contrib directory or inside the clojure-contrib.jar?
How to download, install, and setup the libs in the page?
Added
After updating leiningen, I checked that (use 'clojure.contrib.str-utils) works fine. But, (use 'clojure.contrib.repl-utils) gives me the following error.
[Thrown class java.lang.IllegalStateException]
Restarts:
0: [QUIT] Quit to the SLIME top level
Backtrace:
0: clojure.lang.Namespace.warnOrFailOnReplace(Namespace.java:88)
1: clojure.lang.Namespace.reference(Namespace.java:110)
2: clojure.lang.Namespace.refer(Namespace.java:168)
3: clojure.core$refer.doInvoke(core.clj:3288)
4: clojure.lang.RestFn.invoke(RestFn.java:411)
5: clojure.lang.AFn.applyToHelper(AFn.java:163)
6: clojure.lang.RestFn.applyTo(RestFn.java:133)
7: clojure.core$apply.invoke(core.clj:542)
8: clojure.core$load_lib.doInvoke(core.clj:4781)
9: clojure.lang.RestFn.applyTo(RestFn.java:143)
--more--
(require 'clojure.contrib.repl-utils) work, and I can use (clojure.contrib.repl-utils/show #{}), but (refer 'clojure.contrib.repl-utils) gives me an error.
And here are some more question.
Why (use '..repl-utils) causes an error, whereas str-utils does not? What's the difference bewteen the two libs?
I'm not sure what you mean by standardized, but contrib doesn't make backwards breaking changes without good reason. Some things are occasionally moved to core, if they're sufficiently important -- I seem to recall sequence functions doing that, and likely the string functions that you're thinking of.
Re: Leiningen: a new version just came out. In any case, it sounds like you might have a version conflict.
Regarding the classpath: the source of many unpleasant problems until you get used to it (or it was for me). It could be either of the things you mention, given the context, we're almost certainly talking about clojure-contrib.jar.
To download etc. there are various methods. The easiest method, in virtually all cases, is to list them as a dependency in the project.clj file for your project. In other words, use leiningen. You can also download them from clojars. Or you can clone their github repos, and compile them individually, and copy them into the lib directory of your project. But seriously, just use leiningen.
A lot of functions in clojure-contrib moved into clojure core in Clojure 1.2. The diffrence between now and 1.1 is about the same as the growth of clojure.core.
get the leiningen update
don't know I just use leiningen
Just add it to your project.clj in leinigen
Related
I have a clojure script that I've been running for several years now.
Recently I had to do a reinstall of leiningen and java 8.
When I run the code I now get multiple StackOverflowErrors on third party libraries.
E.g.
StackOverflowError org.apache.commons.math3.util.FastMath.cosQ (FastMath.java:1850)
and
StackOverflowError clojure.lang.Numbers$DoubleOps.combine (Numbers.java:571)
I would post code but it happens now at multiple points in my code and on third party libraries??
without a stack trace and some code, a specific anser will be hard to find, so here is a general method for these things:
Part 1 "what was running before":
recreate your old environment, by digging through the logs, reverting to a backup etc. then run:
lein deps :tree 2>&1 > old-lein-dependencies
the 2>&1 part ensures that the version range and conflict warnings
are included in the output.
Mark down the leiningen version and java version:
lein version
Part 2: "what is running now"
Repeat the steps and record the same information as before:
lein deps :tree 2>&1 > new-lein-dependencies
lein version
java -version
Part 3: Diff and Compare
pick through all the differences
diff -u old-lein-dependencies new-lein-dependencies
there will be a big block of differences at the top where lein prints all the important warnings. The final clue is almost always here, though it's often not easy to recognise up right away.
Part 4: Do Science
go through every version change, starting from the initial configuration by pinning the versions in the project.clj until you find the change that breaks things. A convenient way to pin these is with the :managed-dependencies block in the project.clj file. It looks something like this:
:managed-dependencies [[http-kit "2.3.0-alpha4"]]
and repeat the process of switching out versions till you get a handle on where the change was introduced. For me this has almost always been the result of using a version range in a dependency rather than a specific version. I'm not too enthusiastic about version ranges anymore :-/
So I could not compare the previous setup as it was on a machine that was wiped clean.
I found that an error had crept into one of the math formulas executed by the tool which basically called itself repeatedly resulting in the stack overflow error.
I try to run a cppcheck analysis over my code, which has the following file structure:
/code/module_1/src/a.cpp
/code/module_1/src/b.cpp
/code/module_1/test/c.cpp
/code/module_2/src/d.cpp
/code/module_2/src/e.cpp
/code/module_3/test/f.cpp
I'd like to run an analysis excluding all test code. Is this possible with a command like "cppcheck -itest"? It doesn't work for me, although I think it should, according to the docs:
...Directory name is matched to all parts of the path.
I'm using version 1.69. I know I could mention all test directories separately (which does work, I checked), but the number of modules is too high to do this for many analyses reasonably.
Is this possible?
I installed Cppcheck to do some tests and it seems the -i implementation is a bit bonkers. However, I managed to achieve what you want.
Solution: use -itest\ instead of -itest (this was in Windows; maybe Linux needs -itest/)
Rationale: in my tests, -itest worked only if there was a .\test\ directory, in which case even .\a\test\a.cpp was excluded. With -itest\, however, such exclusion took place regardless of the presence of .\test\ directory.
This seems like a bug which the developers ought to weed out, but, in the meantime, you can succeed using the above workaround.
This is a late response to an old question, but perhaps this will help other latecomers like myself.
Disclaimer: This answer is for Windows.
It seems as if v1.79 has remedied the OP's issue. The following command line syntax has worked for me:
cppcheck -itest code
In this example, "-itest" weeds out any occurrence of the "test" directory, as originally (and correctly) assumed by the OP. In addition, the code folder is found next to the cppcheck.exe. This will be the root of the recursive source-code scan.
I'd use something like:
cppcheck /code/module_1/src /code/module_2/src /code/module_3/src
I decided to start using the Git version control system for my C++ project. I'm new to version control. For the trunk things are simple, I just commit all the project versions I have. I kept each version as a separate folder because I knew I'd very soon use Git. But I encountered a problem with my branches.
At some stage of the development, I decided there's one class I want to develop in a branch. Without version control, I had to use make a "manual" branch. I copied the most recent header file and source file of that class to a separate folder and started working there. I made several versions there to work with simultaneously. One version was the first prototype of the class according to the plan (for which I made the "branch"). Then I added another file, in which I copied the first one but removed things that seemed to not be necessary. This way I have 2 versions, one with all my ideas and features, the the other one just with what I really use in my code, without what's not in use at the moment.
But then I added more. As development went on, I decided it may be a good idea to make that class a template. So I added a third version, which is just like the second one, but now some functionality implemented using polymorphism is implemented using a template. And I can't tell yet which version is the best, as it's too early to tell, so I want to have all 3 together.
Then I made another special file: A copy of the third version header file, in which each line can be marked or not marked. Marked means I use that specific method or I'm sure it's going to be in use very soon, otherwise the line isn't marked.
Then, some time later, I started a new branch. And for that branch I needed a new version of that class developed in the first branch. So I just copied one of the versions to the new branch's folder and started working there. Now again I had some kind of auxiliary file: I had 2 files, one from which I delete class methods I use, and one into which I write new methods I need to have.
Now I want to start using Git and I wonder: For all the project's text files, plans, diagrams, etc., it obvious - I keep them outside the Git repo. Whenever collaborative editing is needed I can set up a wiki or something like that. But for all those copies of the same header file, and for those auxiliary "marked" files, what do I do with them? I mean, it's fine by me to have them all in a branch, but what happens when I merge a branch into the trunk? I don't want to have all these copies and versions and lists, just the one final class file I've made.
On one hand, these are C++ source files used while coding. On the other hand they're not part of the pure source code of the software package, they just help me while I work but will never get compiled because in the end there's just the final version of the class which I chose to merge, and all other aux files, lists, etc. are kept just for reference.
What would be the best thing to do?
Thanks for reading my long story :)
EDIT: It's a local repo on my personal computer
Always keep documentation in same repository as source code. If you do not, your documentation will rot. It is becouse documentation is written agains some version of your software, so it has to develop the same way as software develops.
If your documentation is automaticaly generated or compiled into another format, commit only source data, makefile and configuration of generator, just like you do with source code.
What you describe is the normal use of branches: You have your master branch ("official", if it where) and a branch to develop a new feature (it doesn't really have to live in a separate directory, if I understand you correctly). Periodically you synchronize the feature branch with the master, either by rebasing it on the master or merging its changes in. In its turn, you can well have subordinate branches in which you try out approaches to develop the feature, handled with respect to the feature branch just like that one respect to the master. But in that case you have to be careful whenever you rebase.
You should keep any data that isn't easy to recreate in the repository, be it source code, documentation or even design sketches. Stuff that can be recreated (object code, automatically formated documentation, ...) should be kept out (any change there will create a difference to be checked in). Your repository (particularly not published branches) is your own workspace, it can be all the messy you like.
Take a look at the book mentioned at the git homepage.
Well, that’s clearly documentation and not source code, so you should separate it from your source code. As your documentation seems to be branch dependent, you should still check it into the repo, but in a separate doc directory.
About the merging: How a merge works is up to you in the end. Git just has a default merge strategy which is what most people want most of the time. But if you say that a merge into the main branch should just bring the code and not the docu, then that’s fine. Just merge that way:
git merge mybranch --no-commit
rm -rf **docu-dir**
git add -A
git commit
After defining variables, functions, etc., can you save what you have done on the REPL too an text .clj file?
most people work with the repl through an editor such ad Eclipse/Emacs/vim and that editor has the ability to save the repl, though without some diligence on the developers part this will likely be an incomplete record of what happened. Some of the state of the repl may have come from loading files etc which will be in a different state.
So the short answer is typically not.
In Linux (mine = Ubuntu 16.04.2 LTS) if you are using lein then check for .lein (hidden directory) and look for repl-history. You should find the commands that you have typed or pasted into the REPL. This can be a source for later edit - I use geany...
I am answering the parenthetical part of your question. For me, the Clojure REPL is very useful for testing functions and proving out concepts that take no more than a few lines. I will often put hooks in a module that is not the main, just so I can load a file and run it through a couple of functions. I can also do this from main using the same mindset; that is write a debug function.
I found the Eclipse plugin to be quite useful, but I do not use it much these days, mostly Vim and running the module with one or more special functions and running the main. I don't know of any way to save REPL state.
I am trying to go through the process of creating a jar file from a simple clojure file. Below is my clojure code:
(ns app.first (:gen-class))
(refer 'clojure.core)
(defn -main [& args] (println "this program worked!"))
I am using these instructions to create the jar file: http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips
I see the error "java.io.FileNotFoundException: Could not locate app/hello__init.class or app/hello.clj on classpath: (NO_SOURCE_FILE:0)" when I try to complete the (compile 'app.first) step.
The only difference between my attempt and the link is the name of my file (first.clj instead of hello.clj).
Can anyone see where I am going wrong? Or for that matter, all I want to do is learn how to create a jar from a clojure file, so if anyone knows of a better/easier way to do that, let me know.
It's better to use Leiningen for such tasks - it allows to maintain dependencies, and packs all necessary components into jar file
I'm rusty on this, but I heard about other people with similar problems.
I think it's helpful to remember that the classpath you indicate points to the root of your class tree, and package names end up creating subdirectories within that tree. Awkwardly stated, but I hope you get the idea. Thus, I think you need to do some kind of gymnastics with creating directories to match the "app.first" -> "/app/first" hierarchy.
Sorry, that's as close as I come to a sensible and useful answer. Hope this helps you.
EDIT:
The Prime Directive of Computer Science: It only works if you do everything right! I spent almost 10 minutes fiddling with this but was finally successful.
Here's what I needed to do to get your program to compile:
created a directory app, and within that, first.clj with your code.
checked for the *compile-path* by doing (pr *compile-path) within Clojure. It said "classes".
created a second directory classes parallel to app.
in the shell, did export CLASSPATH=.:./classes
in Clojure, did (compile 'app.first)
... and I found a bunch of class files in classes. JARring those should be a snap.
I found it very helpful to run (doc compile) because that reminded me of the requirement to have a directory to satisfy the requirement for a *compile-path*.