brandonbloom / backtick Goto Github PK
View Code? Open in Web Editor NEWClojure's syntax-quote reader macro as a normal macro
License: Eclipse Public License 2.0
Clojure's syntax-quote reader macro as a normal macro
License: Eclipse Public License 2.0
Fixing http://dev.clojure.org/jira/browse/CLJ-1403 will probably break ns-resolve-sym
.
/cc @Bronsa https://twitter.com/Bronsa_/status/605091084449005569
Hi, looks like the blog went down at some point.
I'm not sure if this is temporary, but the wayback machine has a copy: https://web.archive.org/web/20160322115942/http://www.brandonbloom.name/blog/2012/11/23/templating-clojures-backtick/
should
(ns backtick
(:refer-clojure :exclude [eval resolve]))
just be
(ns backtick
(:refer-clojure :exclude [resolve]))
?
Hi -- backtick is really awesome! We're using it to provide inline Clojure code for Alda. It mostly works great, but there is still one wrinkle that we haven't quite been able to solve -- symbols within a let binding are resolved just like any other symbol. This may or may not be a solvable problem, but at any rate, I wanted to see if you have any ideas.
Our use case: We want to read Clojure code from strings and evaluate it within the context of the alda.lisp
namespace, which has a bunch of useful things defined for the user's convenience.
(defquote alda-lisp-quote
#(if-let [{:keys [ns name]} (meta (ns-resolve 'alda.lisp %))]
(symbol (str ns "/" name))
%))
(defn read-to-alda-lisp
[code]
(load-string (format "(alda.parser/alda-lisp-quote %s)" code)))
The idea is that each symbol attempts to be resolved in alda.lisp
(if this succeeds, we get something like alda.lisp/tempo
or clojure.core/println
), and if this fails, then the symbol stays as-is (e.g. x
), so that when the code is eval'd, the Clojure reader will attempt to read it as a locally scoped symbol or within the current namespace, depending on the context.
This appears to work in every case except for the one where you create a local binding that happens to have the same name as something defined in alda.lisp
-- it will resolve to alda.lisp/that-thing
instead of that-thing
.
Do you know if there is a way, using backtick, to only attempt to resolve a symbol if it is not supposed to be in some scope? The Clojure reader apparently does this somehow, but I'm not familiar enough with Clojure's internals to know how exactly.
I am heavily using the backtick/template
macro in my application. The macro is unfortunately not compatible with recent changes in clj-kondo. However, I have created a compatibility layer for cli-kondo. This basically means a proxy macro expander must be provided for cli-kondo to use rather than really expanding the macro.
I am happy to provide this compatibility layer as a contribution to the backtick
project, but I'm not sure the best way of doing that.
If you are interested in discussing this, let me know.
It would amount to me submitting a PR which would add a kondo.exports
at the top level of the library. That directory would provide an alternate macro expansion which clj-kondo's limited clojure interpreter would use rather than loading the real one.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.