Fork me on GitHub
#clojure
<
2018-02-25
>
jmb00:02:49

Hey guys. I have a problem with one of my Clojurescript functions. I have two functions that use the ^:export metatag. One of them works just fine when called, but the other one doesn't. I keep getting the message Uncaught TypeError: cljs.tracker.bluetoggle is not a function. I've restarted my server multiple times, but it still doesn't work. I have no idea what's going on and why one function works but the other doesn't.

joelsanchez00:02:57

the most straightforward way to debug this would be to evaluate cljs.tracker at the JS console

joelsanchez00:02:37

why do your namespaces begin with cljs though?

jmb01:02:16

I just made a folder named cljs to remind myself that all Clojurescript files are there

jmb01:02:54

I just realized that ^:export hasn’t been exporting my function for some reason

uwo02:02:12

any recommendation on a general approach to finding the ‘difference’ of two trees? something like

(let [[nu old _] (clojure.data/diff t1 t2)]
  ;; old with all 'updates' from nu removed
  ;; (something/difference old nu)
  )

uwo02:02:34

basically looking for the obsolete parts of old

sundarj02:02:44

@uwo clojure.set/difference?

uwo02:02:02

@sundarj I only chose the word difference to be evocative. this needs to word on arbitrary clojure data (edn)

sundarj02:02:55

not sure what you mean then, sorry 🙂

noisesmith02:02:55

edn is a string format

uwo02:02:15

forgive me for being imprecise. yes edn is a serialization format. “clojure data” then.

seancorfield05:02:22

@uwo Are you looking for clojure.data/diff perhaps?

boot.user=> (doc clojure.data/diff)
-------------------------
clojure.data/diff
([a b])
  Recursively compares a and b, returning a tuple of
  [things-only-in-a things-only-in-b things-in-both].
  Comparison rules:

  * For equal a and b, return [nil nil a].
  * Maps are subdiffed where keys match and values differ.
  * Sets are never subdiffed.
  * All sequential things are treated as associative collections
    by their indexes, with results returned as vectors.
  * Everything else (including strings!) is treated as
    an atom and compared for equality.
nil

uwo14:02:55

nearly. I’m working with the results of clojure.data/diff, so if let [[new' old' both] (clojure.diff new old)], I’d like to find something like the “difference” keypath-wise of old’ and new’. old’ is going to contain both the key paths that were updated and ones that never existed in new. I’m looking for only this latter category of obsolete datoms

dottedmag07:02:58

Could somebody recommend a syntactic term rewriting library for Clojure? I have tried using core.match and termito, but they don't seem to be featureful enough. The typical conversion rule I'd need is something of (select ?a ["foo"])(:foo ?a), (select ?a ["foo" "bar"])(get-in ?a [:foo :bar]), (select ?a ["foo"] :or ?b)(:a ?a ?b), (select ?a ["foo" "bar"] :or ?b)(get-in ?a [:foo :bar] ?b).

dottedmag07:02:29

Or maybe not a syntactic rewriting, if there is another, simpler, way to achieve the same result.

borkdude07:02:57

When I run clj -Sdeps '{:deps {org.clojurescript {:git/url "" :sha "3f4084efcb5cd92cceb8ca30765144691d8cfd7e"}}}' -m cljs.main -re node where will clojurescript be cloned?

dominicm08:02:51

@borkdude to .gitlibs in your home

matan13:02:48

wondering how would you personally manipulate all vals of a map in a uniform way

matan13:02:53

I mean elegantly

schmee13:02:42

@matan that is a very vague question, do you have a more specific example of what you’re trying to do?

matan15:02:18

Sorry about that. I guess Spekter should have something, but I just rolled my own

(defn update-all-vals [input-map f]
  (apply merge
     (map
        (fn [[k v]] {k (f v)})
        input-map)))

schmee15:02:25

Specter is (transform MAP-VALS f input-map)

schmee15:02:04

if you need it to be fast, you should use that instead of your version

matan15:02:39

Sounds like this isn't very cpu efficient isn't it (like most of the functional abstractions)

danboykis15:02:43

@matan if i was to roll my own I'd do something like: (defn update-all-vals [input-map f] (into {} (map (fn [[k v]] [k (f v)])) input-map))

matan16:02:59

Thanks for the simplification 🙂

danboykis15:02:33

it saves you from doing a merge and creating intermediate maps

danboykis15:02:08

if you want to optimize it there's fairly non-invasive stuff you can do to make it go faster, but i wouldn't bother unless it proves to be a bottleneck

Charles Fourdrignier15:02:30

Is Clojure needed ? You could find solutions via shell (awk, sed, ...). Examples : nl -w2 -s',' a.txt > b.txt or awk '{print NR "," $0}' a.txt > b.txt

foxlog15:02:12

🙂 beautiful!

pablore19:02:08

Are there any maintained wrapper for JavaFX? I have seen fn-fx and clojurefx but they all seem abandoned

ghadi19:02:37

a lot of clojure libraries seem that way -- but aren't.

eskos20:02:52

There simply isn't anything to fix 🙂

pablore20:02:21

With abandoned I mean the implementation is not even finished

yogidevbear21:02:36

Does anyone know of an efficient way to work over a matrix from a random point within the matrix, not using row or column major order, but more of an adjacent style ordering?

dpsutton21:02:43

@yogidevbear what does the data structure look like? Seems like row and column addressing are standard. Would you make a zipper or something similar? Don't know of another common way to do it

yogidevbear21:02:42

For example, if I have this vector of vectors:

[[0 0 0]
 [1 0 0]
 [0 0 0]
And I want to walk it from a particular coordinate (e.g. [1 2] = second column, third row), going up, right , down and left from that point, and then doing the same from each successive point, based on a logical check

yogidevbear21:02:38

Sorry, I know this is rather abstract

yogidevbear21:02:04

So I'd want to walk the matrix, ignoring the cell with the 1 value

yogidevbear21:02:21

[[0 2 3 0 1]
 [0 0 1 0 4]
 [1 0 0 0 6]
 [0 2 0 4 5]]

yogidevbear21:02:23

Or taking the example above, if I started with a zero on the second last row, walk all adjacent cells, and if they have a zero, update that zero with a value and repeat for it's adjacent cells

yogidevbear21:02:47

In that example, all zeros except for the bottom left one would be updated

seancorfield21:02:32

I'm not sure that you can escape the row/col index approach -- but for any given x/y pair, you can generate the set of neighbors as x/y coords tho'...

yogidevbear21:02:58

So if I was changing them to 9's, the result would look like:

[[9 2 3 9 1]
 [9 9 1 9 4]
 [1 9 9 9 6]
 [0 2 9 4 5]]

yogidevbear21:02:26

My thinking at present is to have a hashmap to keep coordinates that have already been tested as I move forward

dpsutton21:02:09

There was an advent of code that would have some really good examples for you

seancorfield21:02:21

I'm very unclear what problem you're describing I'm afraid...

dpsutton21:02:26

Check out @mfikes Advent of code sometime

yogidevbear21:02:34

And a function to call that will have a for to get calculate the adjacent cells which can recur

dpsutton21:02:56

I forget what day it was but it had to compute neighbors in an infinite grid and not double count them

yogidevbear21:02:13

Sounds very similar

yogidevbear21:02:32

I've tried some google, but my fu is a bit off on this one

yogidevbear21:02:00

Thanks for the tip Dan, I'll have a look for his repo in a moment

curlyfry21:02:07

Sounds like graph traversal to me, check out the breadth first search algorithm for example

seancorfield21:02:42

You can keep a set of coords that have been checked #{[0 0] [0 1] [1 2]} for example (you said hash map but I think you want a set?)

curlyfry21:02:31

You can think of your matrix as a graph where the neighbour nodes are the cells above, to the left, to the right, or below the current cell

yogidevbear21:02:52

Thanks @curlyfry, breadth first search may be what I'm trying to search for

yogidevbear22:02:01

Why would the following function give me a CompilerException java.lang.IllegalStateException: Can't pop empty vector error?

(defn test
  [X Y MX]
  (for [:up [X (dec Y)]
        :right [(inc X) Y]
        :down [X (inc Y)]
        :left [(dec X) Y]]
    (conj MX :up :right :down :left)))

dpsutton22:02:57

Look into the syntax of for. I don't think you've got the right idea in this one

seancorfield22:02:05

for doesn't use keywords, it uses symbols (certain keywords introduce conditions and additional bindings so I expect the compiler is parsing your for according to keyword?).

yogidevbear22:02:30

Ah, silly me 🙂

(defn test
  [X Y MX]
  (for [up [X (dec Y)]
        right [(inc X) Y]
        down [X (inc Y)]
        left [(dec X) Y]]
    (conj MX up right down left)))

yogidevbear22:02:45

I was using :up instead of up, etc

seancorfield22:02:52

UPPER CASE symbols... shudder 😆

noisesmith23:02:44

those for bindings still look very weird

noisesmith23:02:06

are you expecting each of the right hand vectors to act like a range?

noisesmith23:02:26

no that doesn't work either