Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brandonbloom/backtick
Clojure's syntax-quote reader macro as a normal macro
https://github.com/brandonbloom/backtick
Last synced: 3 days ago
JSON representation
Clojure's syntax-quote reader macro as a normal macro
- Host: GitHub
- URL: https://github.com/brandonbloom/backtick
- Owner: brandonbloom
- License: epl-2.0
- Created: 2012-11-22T09:32:48.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2023-09-09T17:22:04.000Z (over 1 year ago)
- Last Synced: 2025-01-01T08:10:29.820Z (10 days ago)
- Language: Clojure
- Homepage:
- Size: 28.3 KB
- Stars: 212
- Watchers: 11
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# backtick
A Clojure library providing the syntax-quote (aka quasiquote) reader macro as a normal macro.
## Motivation
Clojure's backtick `` ` `` reader macro, called syntax-quote, complects the
templating of Clojure forms with Clojure's namespaced symbol resolution.Backtick allows you to use the unquote `` ~ `` and unquote-splicing `` ~@ ``
metacharacters for templating forms with or without a custom symbol resolver.Lots more background at .
## Installation
Artifacts are hosted on Clojars:
## Usage
```clojure
(use 'backtick);; Full syntax-quote replacement
(let [x 5 v [:a :b]]
(syntax-quote {:x ~x, s #{~@v "c" inc}}));; Returns:
{:x 5, user/s #{"c" clojure.core/inc :a :b}};; Templating only, no symbol resolution
(let [x 5 v [:a :b]]
(template {:x ~x, s #{~@v "c" inc}}));; Returns:
{s #{"c" :a :b inc}, :x 5}
```Note that while `template` does not resolve symbols, it does support gensyms:
```clojure
(template [x# x# y#]);; Returns something like:
[x__auto__990 x__auto__990 y__auto__991]
```You can create a templating macro with a custom resolver by using `defquote`:
```clojure
(defquote shout-quote (comp symbol clojure.string/upper-case))(shout-quote {:foo bar})
;; Returns:
{:foo BAR}
```Corresponding functions are generated for every quoting macro:
```clojure
(syntax-quote-fn 'foo) ;; => (quote user/foo)
(template-fn 'foo) ;; => (quote foo)
(shout-quote-fn 'foo) ;; => (quote FOO)
```## License
Copyright © 2012 Brandon Bloom
Distributed under the Eclipse Public License, the same as Clojure.