Ah, yeah, readability is kind of hard to address because folks have different notions of what that means. However, I would argue that having a large LHS and RHS is maybe not so bad.
FWIW I’ve had good success with defsyntax
(see original thread for example), and with using (m/app)
to do futher transformations.
But, again, that perspective is context sensitive.
Oh, yeah, thats a nice way to do it.
Actually, I recently used defsyntax
for just that purpose
Hmmm I was wondering about this. Thanks @timothypratley
I see what you mean. It is subjective indeed.
(defsyntax cool-thing [?a ?b]
{:a ?a :b ?b})
Would give you the ability to match and substitute with cool-thing
.Why do you here use those arguments [?a ?b]
?
(m/defsyntax cool-thing [?a ?b]
{:a ?a :b ?b})
(m/match {:a 1 :b 2}
(cool-thing 1 ?b)
?b)
;; => 2
(m/rewrite {:a 1 :b 2}
(cool-thing ?a ?b)
(cool-thing [?a ?a] [?b ?b]))
;; => {:a [1 1], :b [2 2]}
Out of habit. 🙂
Nice
Gonna give this a try.
@ezmiller77 Checkout https://github.com/noprompt/meander/blob/epsilon/doc/defsyntax.md
If anything isn’t clear in the docs or if you want to improve them etc. open a ticket, pull request, or chat here. 🙂
Here’s an example of what I mean by m/app
https://github.com/timothypratley/happygapi/blob/master/dev/happy/beaver.clj#L154 which can be handy if you have deeply nested stuff that you just don’t want to think about 🙂 i.e. defsyntax is great for breaking up patterns but at some point you still have to put them back together somehow so if the putting togeter
and pulling apart
are colocated I think m/app
wins in those cases /shrug
Thanks to you both for the quick responses. Gonna study these links.
Definitely! I think you will find folks here to be helpful. Its rare that a question gets left on the stack without a response.
Coincidentally, I do need to step away for a moment. 🙂
Normally I might commit this and release, but there were other folks involved in the previous discussions and I want to give them (and others) a chance to share any thoughts before I merge. Tim, I’m looking at you. 🙂
I’ll play around with it tonight
works as advertised :thumbsup: