I have asked this question before (Locating unmatched delimiters in Clojurescript) and I still do not have a sufficient answer.
I would like to get some warning of the line where an error such as a parameter mismatch is being detected by the reader. Clojure usually just throws a very general error naming the file only but no line, etc.
I would like to have either a
- clojure specific tool (something like a lint tool) that provides this information
- advice on reading those stack traces
I have found my problem now and would like to be more precise about the problem I had. I was compiling Clojurescript distributed over code over several files. I knew I had made changes in about three of them when I discovered that the code would not compile anymore. The error message was about a mismatched )
in file a.cljs
on line 1
. However I was quite sure, that I did not change a.cljs
substantially.
So I was taking the usual way that I perform when such an error occurs (that is not too often).
- Indent whole files with vim to see if indentation is going "nuts".
- Use git diff to look for changes in my working copy and the most recent history (I do granular commits) to find spots I changed recently.
This time I did not spot the change that easily. In the end I found out that the issue was a missing ]
in a part of the file where closing parentheses piled up, i.e. something like )]))])
in the middle of some other file c.cljs
. For some reason, vim clojure did not indent the following functions more or wrongly, therefore the indentation based "detection" did not work.
I reallize that there is probably a good reason why the clojure reader is not very good at spitting out the locations of these paren mismatches. Please do not understand my question as being condascending. After having looked for a place for quite some time, I wrote a small (~50 lines) stack-based parentheses matching program (in C++ I have to admit) which handles {([
;
-comments and simple "
strings -- nothing close to a correct parser, yet it pointed me to the right line and characters.
In terms of the quality of Clojure's error messages: Some are poor, yet I am mostly not complaining since Clojure's syntax is so straightforward that mostly I just get the syntax right (semantics is a different topic). Nevertheless for a lisp giving such poor error messages on mismatched parens is a bit unlucky especially for people haven't worked with Lisp before. I know paredit, I have used it (vim-paredit at least) and its a good tool to work with s-expressions. However it does make a few things more complicated and I have had bad experiences mixing paredit and vim-fugitive.
Hacking and contributing to the clojure core as suggested: Might be an option actually, although when browsing through that source code it really takes a lot of effort to dive in. Although at the moment I feel rather like writing a small single-purpose tool to be used with leiningen, it might be simpler that way.
I feel that my post has provoked some people in a way. It did not mean to talk down the clojure project, I am really greatful for clojure developers for providing me programming language.