Fork me on GitHub
#meander
<
2020-07-17
>
JAtkins00:07:06

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.

JAtkins00:07:00

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]]

JAtkins00:07:22

Basically unroll the relationship between the numbers and the context

Jimmy Miller00:07:22

@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.

JAtkins00:07:22

No problem, I just got off work myself.

ikrimael00:07:32

@jatkin once you figure it out, would you mind adding your cases as examples to https://github.com/noprompt/meander/pull/125

👍 3
ikrimael01:07:27

@noprompt cleaned up/merged feedback for the examples from the chat

👍 3
ikrimael01:07:29

figure it's enough of a chunk to submit; i'll start another PR for today onward

JAtkins01:07:10

Trying to read through the source and make out what should make this tick.

JAtkins01:07:11

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])

JAtkins01:07:49

The docstring of scan was immensely helpful. But, if I might ask, why does this work but the other cases do not?

JAtkins01:07:42

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?

JAtkins05:07:16

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.

🎉 9