Git Product home page Git Product logo

backtick's Introduction

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 https://www.brandonbloom.name/blog/2012/11/23/templating-clojures-backtick/.

Installation

Artifacts are hosted on Clojars: https://clojars.org/backtick

Usage

(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:

(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:

(defquote shout-quote (comp symbol clojure.string/upper-case))

(shout-quote {:foo bar})

;; Returns:
{:foo BAR}

Corresponding functions are generated for every quoting macro:

(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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.