Posted on 2025-05-15
(Last modified on 2025-05-17)
| 1 minutes
| 76 words
In case you don’t know it, we can use raw strings, like embedding JS code, in hiccup.
I just found out we can use raw to prevent strings from getting escaped. I used to have to define a dedicated app.js for that, which would need an extra HTTP request.
Hiccup raw in action
Looking back, I should’ve found this at the very beginning, as it’s just mentioned on its GitHub homepage, but somehow I missed it.
Posted on 2025-04-29
(Last modified on 2025-05-17)
| 1 minutes
| 82 words
Sometimes, we may want a few examples of a Clojure API for inspiration while developing, especially when reading other people's or open source code.
With Cider in Emacs, we can run M-x cider-doc to see the docstring for the symbol. We can even use M-x cider-clojuredocs for some examples if the symbol is from the language core.
Running M-x cider-clojuredocs
I happened to find this command recently. I bet I was not the only one who didn't know it, thus I'm sharing.
Posted on 2025-04-23
(Last modified on 2025-05-17)
| 1 minutes
| 57 words
So you're more than excited to find out how Clojure's thread macros can make code clean and concise, you just love it! But at some point you'll be trapped a bit as the threaded argument's positions are inconsistent using -> or ->>.
Luckily, you can use as-> to place the argument wherever you like:
Posted on 2025-04-18
(Last modified on 2025-05-17)
| 1 minutes
| 47 words
It's amazingly easy to group things in Clojure. The language core provides a group-by function directly. Together with many built-in functions or key functions, it creates a ton of possibilities, and we can also bake our grouping function if none is satisfying.
When you’re building a side project, chances are you need to collect user events so that you can understand user behaviors better and eventually improve your product.
Posted on 2025-04-05
(Last modified on 2025-05-17)
| 1 minutes
| 64 words
In Clojure, we can use comment (aka Rich Comment Blocks) for tests or experiments in development. However, since a comment evaluates to nil, you may run into surprising results or even errors if you misuse it.
Comment vs. Discard
In these scenarios, you may tend to use ; to comment them out, but a better choice is to use the discard reader symbol #_.
Posted on 2025-02-22
(Last modified on 2025-10-17)
| 16 minutes
| 3250 words
Intro
A few years ago, I made a simple web app in Flask to deal with some text processing problems from my daily work. It has two main features:
Feature #1: generating compile_commands.json for GNU Makefile projects written in C/C++ using the output of the make command. Because, unlike CMake, the make command can't generate it.
Feature #2: extract text using Python regex. It's handy when I feel like sed/awk/grep's line-oriented processing isn't enough for the task at hand.
BTW, I'm improving my English by watching YouTube videos every single day; If you're also learning English, or any languages, LanguagePuppy can definitely help you. It's a Chrome extension I developed using Clojure. Check it out:
Posted on 2025-01-05
(Last modified on 2025-02-20)
| 1 minutes
| 190 words
I was wondering how to construct a multi-key map conditionally while I was coding in Clojure. Ideally, I would like to build it "in one pass" like {:bar 2 (when true :baz 3)}, but from what I had collected from Blue Sky, it seemed that's impossible, or it's just not an idiomatic way to program like that in Clojure. (Or, is this just a side effect of writing too much imperative code?)
Here is the outline for my cider tutorial on YouTube, covering basic things you need to know to get started with cider, and starting exploring the fun of clojure programming with the REPL-driven programming approach.
Jack In to a REPL
C-c M-j (cider-jack-in-clj)
start a nREPL and jack in.
It works in a project or with a sole .clj file.
M-x cider-connect-clj
run the command and then fill in hostname and port.
It could be useful in some cases. e.g. on Windows, I can start the nREPL manually and then connect to it separately.
Evaluate Things
C-M-x (cider-eval-defun-at-point)
evaluate current top-level form.
C-x C-e (cider-eval-last-sexp)
evaluate the preceding form.
C-c C-k (cider-load-buffer)
evaluate/load the current buffer.
C-c C-p (cider-pprint-eval-last-sexp)
Pprint the result in a dedicated buffer.
Great thing to do when the result is too large to fit in the echo area.
Note: I prefer to use the same key bindings as for Elisp, given that
cider might bind a few keys to a single command!
It's ok to use a path as a key for a clojure map.
At my first try, I somehow came to the conclusion that it's not ok, while I was refactoring the live reload for clay. And later I found that it's totally fine to use it as a key. 😞
Use fs/path to construct file/directory paths, for example, (fs/path "/tmp" "foo" "bar" "baz.clj") will result in a path object for /tmp/foo/bar/baz.clj on linux.
If you're coming from Python, it might remind you of os.path.join(path, *paths).
Use fs/createdirs for mkdir -p, though its name is a bit misleading, I first thought it's for creating a few dirs.