Python's f-string for Clojure!
After switching to Clojure the only thing I really missed was the f-string syntax. Remember?
name = "John Smith"
print(f'Hello, {name}!')
>>> Hello, John Smith!
Real handy. So as an excercise, I made the same for Clojure:
(require [blaster.clj-fstring :refer [f-str]])
(def who "John Smith")
(f-str "Hello, {who}!") ;; => "Hello, John Smith!"
f-string
has no dependencies, only the standard library.
You can install from Clojars:
{com.github.blasterai/clj-fstring {:mvn/version "1.1.1"}}
Some examples, including escape syntax:
(require [blaster.clj-fstring :refer [f-str]]
(def who "John Smith")
(f-str "Hello, {who}!") ;; => "Hello, John Smith!"
;; It also works with arbitrary expressions
(f-str "1 + 1 = {(+ 1 2)}") ;; => "1 + 1 = 3"
;; And it has a simple escape syntax in case you actually need the curly brackets
(f-str "This is not evaluated '{spam}");; => "This is not evaluated {spam}"
(let [where "Sparta"]
(f-str "This is {where}!"))
Run the project's tests (they'll fail until you edit them):
$ clojure -T:build test
Lint with Eastwood:
$ clojure -T:build eastwood
Build a deployable jar of this library:
$ clojure -T:build ci
Bump version:
$ clojure -T:build bump-version :bump :patch
Deploy to Clojars:
$ clojure -T:build deploy
Your library will be deployed to com.github.blasterai/clj-fstring.
Copyright © 2021 blaster.ai
Distributed under the Eclipse Public License version 1.0.
Can you improve this documentation? These fine people already did:
Mikhail Beliansky, MB & licht1steinEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close