I guess this is the source of my confusion. Why does the code following not return (1 2 3 4 5)
, but instead throw an error?
(m/search {:a [1 2 3 4 5]}
{:a [?x ...]}
?x)
;; => actual
Zero or more patterns may not have references to unbound logic variables.
If I break my case down an actual usage example, this is what I have as input data:
[{:context-tag :one-to-five
:a [1 2 3 4 5]}
{:context-tag :nine-to-five
:a [9 8 7 6 5]}]
and what I'm trying to get is this:
[[:one-to-five 1]
[:one-to-five 2]
[:one-to-five 3]
[:one-to-five 4]
[:one-to-five 5]
[:nine-to-five 9]
[:nine-to-five 8]
[:nine-to-five 7]
[:nine-to-five 6]
[:nine-to-five 5]]
Basically unroll the relationship between the numbers and the context
@jatkin Thanks for giving an input and output case. I am sadly busy right now, but if someone else doesn't help you before then I can post an example tonight.
No problem, I just got off work myself.
@jatkin once you figure it out, would you mind adding your cases as examples to https://github.com/noprompt/meander/pull/125
@noprompt cleaned up/merged feedback for the examples from the chat
Merged it!
figure it's enough of a chunk to submit; i'll start another PR for today onward
Will do
Trying to read through the source and make out what should make this tick.
AH-HA!
(m/search {:context-tag :one-to-five
:k [:aa :bb :cc :dd :ee]}
{:context-tag ?context
:k [_ ... ?k . _ ...]}
[?context ?k])
; =>
([:one-to-five :aa] [:one-to-five :bb] [:one-to-five :cc] [:one-to-five :dd] [:one-to-five :ee])
The docstring of scan
was immensely helpful. But, if I might ask, why does this work but the other cases do not?
I'm especially confused by the additional _
required. I would assume those would bind to :aa
and :ee
. I guess by "match anything" it means even match a blank space?
I think I just had a breakthough... Holy freaking cow is this awesome! Just wrote in 2 lines something that would easily be 15 lines of regular mapping/filtering/reducing.