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.
Related
I can create an uberjar that is composed of lots of class files, originally Scala, Java, Clojure. The problem I have is that when I run java -jar my-server.jar it crashes with:
No configuration setting found for key 'akka.version'
This is to be expected and has a maven solution. The yellow writing on the accepted answer here is basically Akka saying "you shouldn't build uberjars with Akka jars in them, as then Akka won't be able to find its .conf files."
I am trying this as a lein solution:
:pom-plugins [[org.apache.maven.plugins/maven-shade-plugin 2.2]]
I have a local maven repository (by this I mean not the ~/.m2 one, but a local one that is used to introduce non-Clojars jars into the lein build). Maybe I need to lein deploy localrepo1 for the akka jars again to pick up this new setting - Nope - that didn't help.
Here's some of the stack trace to make it clear where the problem comes from:
Exception in thread "main" com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version'
at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:124)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:145)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:151)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:159)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:164)
at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:206)
at akka.actor.ActorSystem$Settings.<init>(ActorSystem.scala:169)
at akka.actor.ActorSystemImpl.<init>(ActorSystem.scala:505)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:142)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:109)
at com.seasoft.comms.MyPLCActorHolder.createRefToLocalActor(MyPLCActorHolder.scala:39)
Edit I've now looked inside the jar files. There are two akka jar files that both have a reference.conf in them. These files are not correctly merged because (unsurprisingly) lein uberjar doesn't understand the nesting of the property key/values within them.
Specifically the reference.conf in akka-actor_2.11-2.3.9.jar has akka.version = "2.3.9", but this entry has not made it to the merged reference.conf. I altered the uberjar and that fixed the problem, of course giving me the next merge problem. So the fix here is to manually do the merge myself.
And the better fix would be to write a little merging program (with two functions: a predicate and merge) and get it into akka so that people who write build tools can just use it...
Manually merging reference.conf from the two jars and then manually altering the uberjar (overwriting the existing reference.conf) did the trick. The merged file is here.
I believe this problem will occur anytime there are property files that come from different jars that have the same name. For instance log4j.properties also needed to be overwritten.
I changed spark version to avoid this kind of problem. Spark 2.1.0 does not depend on Akka, and does not have the Akka reference.conf problem.
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
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.
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
Clojure has introduced me to the concept of Lisp syntax, and I'm interested, but it's a pain to get the Clojure repl set up and use it on different machines. What other resources are there out there for actually on-the-fly testing and playing with Lisp syntax?
I'm imagining something like a website where you can input rudimentary code, or a browser add-on, or even just a standalone application that steps you through Lisp (something that runs on Linux/Ubuntu).
Haven't been able to find anything like that to start me off in a simple/accessible way.
The SISC Online REPL is exactly what you need. It accepts Scheme syntax, which is a variant of Lisp.
For a standalone app I like PLT Scheme because it seems to work the same on every platform I've tried. I was previously using MIT Scheme on Ubuntu, but decided to switch when I bought a new machine with 64-bit Vista installed.
At the risk of losing all of my rep points, try newlisp.
I've used LispBox in the past. Easy to set up and get going, but I have to admit that Emacs is second nature to me. If you're unfamiliar with that, you may can use another editor, but getting intimate with Emacs will help you live comfortably in Lispville.
It's not hard to get to a Clojure REPL nowadays.
Go to http://build.clojure.org/ and download clojure.jar.
Install a JVM.
java -jar clojure.jar
This should work on any machine that has a JVM installed.
For more fun, install rlwrap and use rlwrap java -jar clojure.
For learning Lisp the LispWorks personal edition is fine: LispWorks downloads. There are versions for Mac OS X, Windows, Linux and FreeBSD. All have the same user interface capabilities and this includes an editor and listener - plus lots of other tools. On Linux and FreeBSD in currently (LispWorks 5) uses X11/Motif for the GUI - this will change in a future version (LispWorks 6) to GTK. So to run it now under Linux, you need to have the Motif lib installed. Other than that using it is relatively painless. There are some restrictions to it (only 5 hours runtime, then you need to save and restart, ...) and the full version is commercial. But for learning some Lisp basics, it is quite good.
Franz has an online REPL for Allegro Common Lisp.
http://www.franz.com/products/allegrocl/prompt/
codepad.org is a nice simple online way to enter and run code (in many different languages, including Scheme). I use it all the time for testing out snippets of code to use in SO answers.
I won't edit Lisp code without an editor that does what Emacs will do with the following configuration:
(define-key lisp-mode-shared-map "[" 'insert-parentheses)
(define-key lisp-mode-shared-map "]" 'move-past-close-and-reindent)
The former inserts balanced parentheses. If you give it a numeric prefix argument, it inserts that many nested pairs. By default, it inserts one. If you have a text region marked, it encloses that region in the innermost inserted pair. That means that you'll never open a parenthesis that's not closed.
The latter is harder to explain, as it's used less frequently. It's more of a navigation command than an insertion command. It confirms that you're done editing the current form and moves the cursor up, out, and past it, preparing for the next likely insertion.
With these keys bound, one no longer needs to use the Shift key to access the parentheses. Also, this leaves the parentheses keys bound as normal, for when sexp repair or a literal parenthesis character is required. I stole the bracket keys because they're used so infrequently in Emacs Lisp and Common Lisp. The bracket characters are still accessible with meta key bindings:
(defmacro make-key-inserter (def)
"Substitute for `self-insert-command'."
`(lambda (arg)
(interactive "*P")
(insert-char ,def (prefix-numeric-value arg))))
(define-key lisp-mode-shared-map "\M-[" (make-key-inserter ?\[))
(define-key lisp-mode-shared-map "\M-]" (make-key-inserter ?\]))
It's not essential to use Emacs, but don't settle for less with another editor that can't at least match this capability. There's also a whole family of commands for navigating and manipulating the sexp tree as a tree. Understanding why that's valuable will require you to fumble around for a while until you stop seeing syntax and start seeing the tree.
Since you're using Ubuntu, I'd just install some of the packages and give them a try.
Common Lisp: apt-get install clisp
Scheme: apt-get install drscheme
These aren't the only packaged implementations, but maybe the easier to get started with. You'll be able to play at a REPL and also run your own scripts through the interpreter.
BioBike provides a full Common Lisp evaluator through the web (with extras like a knowledge representation system, biocomputing, and an alternative visual langauge as well).
If you just want to play with LISP, interactively, quickly, GNU Emacs has a LISP interpreter built in, and listening in the *scratch* buffer. Type an S-expression, position immediately after it, and then hit Ctrl-J to evaluate it. Or <ESC>: will put an Eval: prompt in the minibuffer, accept an S-expression, and evaluate it.
You can define functions, using defun, and test things that way. You have access to ALL of the GNU Emacs built-in functions, and anything you have loaded. If you want to keep things around, you can put them in your .emacs file.
https://github.com/fogus/himera
was very easy for me to setup on a https://www.nitrous.io virtual box. Makes a nice web interface.
Downloading and running clojure-1.6.0.jar on my windows (XP) box was as easy as using this script to run the REPL :
java -cp clojure-1.6.0.jar clojure.main