Skip to content

Instantly share code, notes, and snippets.

@eraserhd
Created September 26, 2019 16:35
Show Gist options
  • Save eraserhd/7af9d44501165acef18f5acfc7c80137 to your computer and use it in GitHub Desktop.
Save eraserhd/7af9d44501165acef18f5acfc7c80137 to your computer and use it in GitHub Desktop.
Small but nice win for Meander
(doseq [attr #{"asset-location" "brand-name" "name" "uuid"}]
(eval
(m/subst
(defrule ~(symbol (str "Branding-" attr))
[EAV (= e '?e) (= a ~(keyword "brand" attr)) (= v '?v)]
=>
(synthesize! '?e ~(keyword "branding" attr) '?v)))))
(doseq [attr #{"branding" "full-name" "uuid"}]
(eval
`(defrule ~(symbol (str "School-" attr))
[EAV (= ~'e ?e#) (= ~'a :educational-organization/type) (= ~'v "SCHOOL")]
[EAV (= ~'e ?e#) (= ~'a ~(keyword "educational-organization" attr)) (= ~'v ?v#)]
~'=>
(synthesize! ?e# ~(keyword "school" attr) ?v#))))
@eraserhd
Copy link
Author

The win: not needing so much escaping.

@noprompt
Copy link

I think you can also do

(doseq [?attr #{"asset-location" "brand-name" "name" "uuid"}]
  (eval
   (m/subst
     (defrule (m/symbol (m/app str "Branding-" ?attr))
       [EAV (= e '?e) (= a (m/keyword "brand" ?attr)) (= v '?v)]
       =>
       (synthesize! '?e (m/keyword "branding" ?attr) '?v)))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment