quoting…
(ns algopop.leaderboardx.ascratch
(:require [meander.substitute.syntax.epsilon :as ss]
[meander.substitute.epsilon :as s]
[meander.epsilon :as m]))
(defn substitute [env pattern]
(-> (ss/parse pattern env)
(s/compile env)))
(defn entity-editor []
(substitute
'{titles ["A" "B" "C"]
values [1 2 3]}
'[:div.form-inline
[:h3 heading]
[:table.table.table-responsive.panel.panel-default
[:thead . [:tr . [:td titles] ...]]
[:tbody . [:tr . [:td values] ...] ...
[:tr . [:td] ...]]]]))
(entity-editor)
^^ is there a way to do this? (this code doesn’t work)Not 100% sure what you are wanting to accomplish.
To be honest I’m not even sure what I’m asking here. I think I might be asking for a runtime feature (which I believe is planned but not something available yet)? But I’m also not convinced I need a runtime feature.
(defn do-some-stuff [!things !stuff]
(m/subst {:things [!things ...]
:stuff [!stuff ...]}))
(do-some-stuff [1 2 3] ["a" "b" "c"])
Is there something you are wanting to do that something like that can’t accomplish?
I’m mainly wondering is whether I can compile a quoted pattern
The circumstances this seems appealing are: a) Editors like cursive treat quoted forms differently (will complain about undefined symbols when not quoted) b) Loading a pattern definition from a file.
So you want to quote the whole expression but also have it substitute?
The specific context I’m thinking of is that I want to allow users to customize how a html element is rendered by providing a hiccup snippet like [:h1 !title]
;; so I was looking in the substitute
macro and it looks like it just calls parse and compile, so it seemed like I should be able to do that too haaaahhahaha but I don’t really grok why it doesn’t work.
I mean, fixing up your entity-editor pattern makes it do something. But not something I think you want.
(defn entity-editor []
(substitute
'{!titles ["A" "B" "C"]
!values [1 2 3]}
'[:div.form-inline
[:h3 heading]
[:table.table.table-responsive.panel.panel-default
[:thead . [:tr . [:td !titles] ...]]
[:tbody . [:tr . [:td !values] ...] ...
[:tr . [:td]]]]]))
I think you are looking for runtime features that we just don’t provide.oh right my pattern was bogus 🤦 thank you… I can make this work like so:
(ns algopop.leaderboardx.ascratch
(:require [meander.substitute.syntax.epsilon :as ss]
[meander.substitute.epsilon :as s]
[meander.epsilon :as m]))
(def ^:dynamic !titles [])
(def ^:dynamic !values [])
(defn substitution [pattern]
(-> (ss/parse pattern)
(s/compile {})))
(def k
(substitution
'[:div.form-inline
[:table.table.table-responsive.panel.panel-default
[:thead . [:tr . [:td !titles] ...]]
[:tbody . [:tr . [:td !values] ...] ...]]]))
(binding [!titles ["A" "B" "C"]
!values [1 2 3]]
(eval k))
=>
[:div.form-inline
[:table.table.table-responsive.panel.panel-default
[:thead [:tr [:td "A"] [:td "B"] [:td "C"]]]
[:tbody [:tr [:td 1] [:td 2] [:td 3]]]]]
and without dynamic vars:
(eval `(defn ~'ff [~'!titles ~'!values] ~k))
🙂