Show HN: Clojure DSL for pattern-matching, parsing and generic programming
scattered-thoughts.net
scattered-thoughts.net
If you think something is especially interesting for some reason, or that a certain kind of content should be featured more, say so! And give a convincing argument for why! That's far more interesting than a double upvote, or trying to somehow limit content you deem inferior, and you will actually influence people in the long run.
Thanks so much for creating and sharing this.
He mentions that core.match is better at efficiently compiling complicated patterns, but little else is said as to exactly why strucjure was made rather than just using core.match.
Strucjure has much more expressive power. Strucjure views are first-class values and can call other views (or recursively call themselves). This allows them to recognise eg context free grammars. Most of the examples in this post cannot be expressed with core.match
Currently, this power comes at the expense of speed but I hope to be able to get reasonably close to core.match for simple patterns. Core.match will always be somewhat faster because it can reorder decisions and eliminate redundant tests.
The generality of Strucjure should not be underestimated :)
(match exp
[([not ([or & rest] :seq)] :seq)] ...)
From the looks of it, solving this problem using strucjure might be a little more elegant.I'm interested to hear your thoughts on Bondi and/or Barry's work.
[edit: ok, so forgive my slow memory. it was olin shivers and ended up as http://www.scsh.net/docu/post/sre.html]
[edit2: gun context http://www.wanderings.net/notebook/Main/BitterAcknowledgment... (cannot find original); meant only in fond, amused recollection, although not personal, having never met him, of course.]
What are your thoughts on implementing reversible patterns?
I'm thinking something like this
(defprotocol Pattern
(extract [this input] "=> bindings")
(replace [this input bindings] "=> new-input"))
This should obey some rule like: (submap? (extract p (replace p input bindings)) bindings)
That would make the data-grammar/generic-traversal experiments much nicer and also cleanly delineates patterns from views. It may also help when I try to do things like generative testing.Not quite sure how that would work for (or ...) and (not ...) patterns, so it still needs more hammock time.