Fork me on GitHub
#specter
<
2016-10-13
>
kenny01:10:07

Is there some sort of problem with specter + Datomic tempids? I get this very strange error:

(rs/declarepath MapWalker)
(rs/providepath MapWalker
                (rs/stay-then-continue
                  rs/MAP-VALS
                  (rs/walker map?)
                  MapWalker))

(rs/transform [MapWalker :db/id]
              (fn [id]
                (d/tempid :db.part/user))
              {:db/id 1
               :foo [{:db/id 2}]})
=> java.lang.UnsupportedOperationException: Can't create empty: datomic.db.DbId
I suspect the error is a red herring..

kenny01:10:14

I can do this without an error:

(rs/transform [MapWalker :db/id]
              (fn [id]
                (d/tempid :db.part/user)
                id)
              {:db/id 1
               :foo [{:db/id 2}]})
=> {:db/id 1, :foo [#:db{:id 2}]}

kenny01:10:40

It's just if the transform-fn returns a tempid that I get the error

kenny01:10:03

I am using specter v0.13.0

nathanmarz01:10:57

@kenny it probably has something to do with clojure.walk interacting with that datomic type

nathanmarz01:10:38

i think you can avoid that situation by doing continue-then-stay instead of stay-then-continue

kenny01:10:45

yes that did it

kenny01:10:08

Why did that make it work?

nathanmarz01:10:07

when you do stay-then-continue, it first updates :db/id on the top-level map. then it does the rest of the path (`MAP-VALS (walker ...) MapWalker`)

nathanmarz01:10:43

when you do continue-then-stay, it does the walk of the submaps first, so at no point does the walk ever go over the datomic types that you produced

kenny01:10:25

Ah I see. Thank you for your explanation 🙂

jlutteringer19:10:11

noob question here: How do I select the values that come before elements that satisfy a given predicate. For example if I had [1 "a" 22 3 5 2 "b" 10] and wanted to select values that occur before strings to get [1 2]. Is this something that is possible?

darwin19:10:31

gave 0.13 another shot, and still having the same issue like 5 weeks ago: https://gist.github.com/darwin/10e6748467e0a13a8f7573c1ae99e4a6 it is calling this function, compiled under :advanced mode with :pseudo-names true https://github.com/binaryage/dirac/blob/6c0c2bc8348eb296174cc72331c031e096af1bda/src/implant/dirac/implant/automation/reps.cljs#L62

darwin19:10:53

looking into it further, I’m going to solve this today, just posting FYI

darwin19:10:31

this.$late1$ seems to be ok, but it does not contain $select_STAR_$

nathanmarz19:10:12

@jlutteringer you could do [(continuous-subseqs (complement string?)) FIRST]

nathanmarz19:10:51

@darwin can you remind me what was causing the issue before?

nathanmarz20:10:17

also, does it still fail under 0.13.1-SNAPSHOT?

darwin20:10:53

we didn’t go deeper into it, I decided to wait if anyone else hits similar issue, downgraded to 0.12 again

darwin20:10:02

I’m going to try the snapshot

nathanmarz20:10:12

does it work under non-advanced compilation?

darwin20:10:05

that is next thing I want to test

nathanmarz20:10:27

can you also wrap that line in (with-inline-debug ...)?

nathanmarz20:10:49

that will print some debugging info that might be useful

darwin20:10:33

0.13.1-SNAPSHOT is broken for me as well, trying to compile it under :whitespace mode and with-inline-debug, unfortunately switching to :none mode would be much more work due to chrome extension packaging restrictions

darwin20:10:37

ah, I’m going in the same footsteps, :whitespace mode is broken due to this parinfer issue: https://github.com/shaunlebron/parinfer/issues/120 and I cannot upgrade because it wasn’t yet published on cljsjs

darwin20:10:07

now I recall, that is why I gave up few weeks ago

darwin20:10:31

I’m going to use parinfer directly as foreign-lib, but it will take me some time until I figure it out

nathanmarz20:10:41

looking at the error more closely, the issue is happening inside of multi-path, so wrapping the providepath in with-inline-debug would be helpful as well

darwin20:10:39

also that “undefined” thing in generated identifier names is suspicious

nathanmarz20:10:42

@jlutteringer just realized you asked something completely different, for that use case I would recommend using zipper navigators or making a custom navigator

jlutteringer20:10:14

I was able to get very close tweaking your example (specter/select [(specter/continuous-subseqs (complement string?)) specter/LAST] [1 "a" 22 3 5 2 "b" 10]) gives me [1 2 10] now I just need to figure out how to drop the last element

nathanmarz20:10:02

well, if the last element of sequence is a string you wouldn't want to drop it

jlutteringer20:10:37

kk, I’ll give zippers a shot, thanks so much for the help!

nathanmarz20:10:15

specter integrates zippers in specter/zipper.cljc

nathanmarz20:10:31

@jlutteringer

(select
        [z/VECTOR-ZIP
         z/DOWN
         z/NEXT-WALK
         (selected? z/NODE string?)
         z/LEFT
         z/NODE]
        [1 2 "a" 3 "b" 4])
;; => [2 3]

jlutteringer20:10:03

you’re the man, thank you so much

darwin21:10:34

getting close to get :whitespace working, now hitting http://dev.clojure.org/jira/browse/CLJS-1547