Fork me on GitHub
#meander
<
2020-11-24
>
noprompt18:11:06

((finder '{?k ?v} identity) {:a 1 :b 2})
;; =>
{?k :a, ?v 1}

((searcher '{?k ?v} identity) {:a 1 :b 2})
;; =>
({?k :a, ?v 1} {?k :b, ?v 2})

noprompt18:11:11

There are details about the implementation in the comments but the gist here is that there is a framework for building up pattern matchers functionally. For now, this framework is largely private and only REPL tested and approved.

noprompt18:11:16

The reason it is private is because 1. there are no unit tests, 2. there is no interpretation for substitution, and 3. pending the substitution interpretation I may want to move things around.

noprompt19:11:27

What is nice, however, is that this model is pretty flexible and once the second items is taken care of and things can be made public, more interesting runtimes can be developed.

noprompt19:11:59

$ bb --classpath src
Babashka v0.2.3 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (require '[meander.interpreter.epsilon :as m])
nil
user=> (m/searcher '{?k ?v} identity)
#object[sci.impl.fns$eval_fn$fn__12966 0x5212d6ab "[email protected]"]
user=> (*1 {:a 1 :b 2 :c 3})
({?k :c, ?v 3} {?k :b, ?v 2} {?k :a, ?v 1})
user=> (m/finder '{?k ?v} identity)
#object[sci.impl.fns$eval_fn$fn__12966 0x62700f6 "[email protected]"]
user=> (*1 {:a 1 :b 2 :c 3})
{?k :c, ?v 3}

👍 3
noprompt19:11:36

The runtime bit is nice. Both searcher and finder use the same factory functions to build up an über factory which takes a runtime and produces a implementation specific matching function.

noprompt19:11:17

In the case of searcher it produces a sequence of results; with finder it reduces the space down to the first one it finds. The details are in the runtime.

noprompt23:11:12

Before I merge, cut, and release, I need to add some unit tests for the interpreter namespace.

❤️ 1