I finally completed my tic-tac-toe program in Clojure. I learned enough about Clojure to be comfortable with it the next time I need to write something. I also have a good development environment in vim. That is probably more important since you really need to be fluent in your environment to be able to focus on learning the language.
I learned a new trick in vim paredit mode. If I want to auto-indent an sexp, I
normally have to do
Jr<Cr> (i.e. join the line, replace the space delimiter
with a carriage return so vim can do the auto-indent). But that means I have
to do it for each line, which gets tedious really fast. The new way is to wrap
the expression in parenthesis and then promote the inner sexp and voila! The
sexp is auto-indented. Instructions:
- Go to the beginning of the sexp in normal mode.
,W. This will wrap it in parentheses
- Go to the beginning of the inner sexp.
,I. This will promote it, i.e. remove the outer parentheses (the one you had just added).
Here’s a list of Clojure functions I found useful: