This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-28
Channels
- # announcements (1)
- # aws (1)
- # babashka (41)
- # beginners (21)
- # biff (7)
- # calva (102)
- # cider (8)
- # cljs-dev (1)
- # clojure (8)
- # clojure-bay-area (2)
- # clojure-dev (30)
- # clojure-europe (40)
- # clojure-norway (52)
- # clojure-sweden (9)
- # clojure-uk (5)
- # clojurescript (15)
- # cursive (7)
- # data-science (1)
- # datomic (23)
- # events (1)
- # fulcro (9)
- # humbleui (23)
- # hyperfiddle (46)
- # introduce-yourself (1)
- # jackdaw (2)
- # jobs (2)
- # london-clojurians (1)
- # malli (13)
- # off-topic (8)
- # re-frame (36)
- # remote-jobs (1)
- # shadow-cljs (4)
- # specter (4)
- # squint (1)
- # transit (4)
- # vim (1)
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
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))
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 syntaxQuotealex, 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
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?
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 [...] ...))
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
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