i recently ran into a scenario when writing some complex macro-generating macros (i know lol) where it would have been helpful to not have syntax quote expansion happen at read time (i was walking a given form and gathering specific symbols). I know that in ancient times (2010), Rich removed the SYNTAX_QUOTE special form from LispReader in favor of the way it works now. Looking at the code, I think a macro in clojure.core that calls clojure.lang.LispReader$SyntaxQuoteReader/syntaxQuote would be enough to accomplish this. Would y'all be interested in such a macro? Otherwise, we have to reimplement that functionality ourselves (like Brandon Bloom's https://github.com/brandonbloom/backtick library).
i'm aware of https://ask.clojure.org/index.php/783/syntax-quote-should-macro-instead-implemented-inside-reader but that question is much more broad than i'm asking.
i suspect that would work but would be a breaking change, so best not to mess with it too much lol
syntax-quote as a macro won't happen, that'd be a breaking change indeed
having it available in clojure.core would be nice I guess
but as you say, there are already libraries that provide it. backtick is one, tools.reader also exposes syntax-quote
if the method was public, it would look like:
(defmacro syntax-quote [form]
(clojure.lang.LispReader$SyntaxQuoteReader/syntaxQuote form))
not quite -- you also need to bind GENSYM_ENV appropriately
ah good point
yeah, libraries are perfectly fine, it's just nice to have features that exist within Clojure already be exposed and available for use
(defmacro syntax-quote [form]
(with-bindings {clojure.lang.LispReader/GENSYM_ENV {}}
(clojure.lang.LispReader$SyntaxQuoteReader/syntaxQuote form)))
lol there we go, with some surgery in lispreader to expose GENSYM_ENV and syntaxQuoteyeah that'd be it :)
shipit
@nbtheduke You can expose that with some evil Java reflection ;)
alex, let's get this into 1.12 😎
https://github.com/clojure/tools.reader/blob/master/src/main/clojure/clojure/tools/reader.clj#L1013-L1017 :P looks quite familiar
btw edamame also allows getting the data structure of syntax-quote back
lol yeah, i read that earlier. just feels like so much effort! that's 1k lines to achieve the same effect as just using the built-in java stuff
user=> (e/parse-string "`(do ~x)" {:syntax-quote true})
(clojure.core/sequence (clojure.core/seq (clojure.core/concat (clojure.core/list (quote do)) (clojure.core/list x))))edamame reads strings, i'm working with clojure data already. i want the effect of syntax-quote, just want to defer evaluating it until the surrounding macro has been evaluated, you know?
yeah that's true
i've put edamame's :syntax-quote to good use in splint, very happy for it there
If you're working with data, you can also prepend a quote:
user=> '`(do ~x)
(clojure.core/seq (clojure.core/concat (clojure.core/list (quote do)) (clojure.core/list x)))
I'm not sure if that's useful in your scenariothat's actually the issue i'm trying to avoid. i have a call to a macro but i'm passing in a syntax-quoted form: (defmacro-g! ... (let ...))` , and then i'm using postwalk on the body. the postwalk sees (clojure.core/seq (clojure.core/concat (clojure.core/list (quote let)) ...)) instead of (let [...] ...) which makes determining certain things hard (is this a vector? how many entries does this map have? etc)
with a proper syntax-quote macro, i could say (defmacro-g! ... (syntax-quote (let [...] ...))) and then postwalk would see (syntax-quote (let [...] ...))
right
and then the call to defmacro-g! returns the form (syntax-quote (let ...)) and then the reader evaluates syntax-quote which would then return (clojure.core/seq (clojure.core/concat ...)) which would do what we want
as we've seen, it's technically a solved problem in the community (officially with tools.reader and communal with backtick), i just think it's a worthwhile addition to clojure.core
not to harp on this too much, just want to point out ways that changes to clojure internals can affect these libraries because they're trying to re-implement existing behavior (https://github.com/brandonbloom/backtick/issues/5) which would be solved by having a built-in syntax-quote
here's my attempt at a syntax-quote macro wrapping the built-in SyntaxQuoteReader functionality: https://github.com/NoahTheDuke/clojure/pull/6
i've signed the CLA so looking at this should be kosher