Some more Clojure in Cirru syntax
I created a GIF earlier today to show how Cirru syntax is parsed, like `$` and `,`, also parentheses and indentations, here’s the original video:
Cirru syntax is a text-based solution for Cirru project. I love it and wrote JavaScript in Cirru syntax for the past months. As I begin digging deeper into Clojure and reagent, I have to update the “Cirru Sepal in Clojure” project in order to make it work with my ClojureScript code. And it’s now a lot better after polishing.
There was a post weeks ago introducing Sepal.clj and I want to talk about the updates in Sepal.clj and the changes on lein-cirru-sepal:
First, about Sepal.clj
I read a post last Friday and it was quite interesting.
In my earlier code, `macroexpand` added namespaces before my functions since I used `quote` with`unquote`and `unquote-splicing` so the generated Clojure code looks quite boring. However as Colin Jones pointed out in that post, there’s a trick to generate a symbol without getting namespaced:
user=> `[:a ~(+ 1 1) ~'c]
[:a 2 c]
And it turned out to work very well, the generated code looks very neat, like someone wrote it.
And about `lein-cirru-sepal`
As I began to generate ClojureScript with Sepal.clj, I have to deal with more scenarios on directory naming, also with the file extensions. It got quite complicated:
- in `project.clj`you need to specify `:cirru-sepal` to decide the `:paths`, which is a vector of strings, for example `[“cirru-src-clj” “cirru-src-clj”]`. The plugin will just write files to new folders by removing “cirru-”.
- Cirru files have to be named like `a.clj.cirru` and `b.cljs.cirru` so that the plugin can simply generate files with the right extensions.
Except for these changes, you may still use `lein cirru-sepal watch` to compile code automatically. It’s very like what we did while writing CoffeeScript in the old days.
Actually, since `lein-cirru-sepal` is watching files with hawk, there might be a bug the change events not fired. We may discuss in the issue below to see if we can solve it:
I have already wrote in Sepal.clj for several hundreds lines of code. Indentations is guiding my eyes really well, and I think that’s the main reason I persuaded myself to go out of my comfort zone and enter the world of Clojure. Actually Sepal.clj is more fun than CirruScript is thanks to the S-Expressions.