Fork me on GitHub

Hi, i have a question about growing vectors as refs. I can't seem to update a vector in a ref:


(def agent-pool (ref []))
(dosync (alter @agent-pool concat (filter odd? [1 2 3])))
(concat [] (filter odd? [1 2 3]))


line 2 does not work, line three does.


CompilerException java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to clojure.lang.Ref, compiling:(nubank_task/core.clj:25:1


(alter agent-pool


you need to alter the ref, not the dereffed value


wonderful, thx!


and another:

(def data (ref [{:a "1"} {:a "2"} {:b "1"}]))
(defn remove-by-a
  [value data-ref]
  (dosync (alter data-ref remove #(= value (:a %)) )))
(remove-by-a "1" data)
gives IllegalArgumentException Don't know how to create ISeq from: nubank_task.core$remove_by_a$fn__4390$fn__4391 clojure.lang.RT.seqFrom (


alter will call your function with the ref's value and then the arguments so you'll end up with (remove ref-value #(= value (:a %)) rather than (remove pred coll)


and the error there is saying it doesn't know how to turn that predicate into a collection


so the problem is with remove's argument order?


is the solution to write a wrapper around remove that switches arg order?

Ian Fernandez16:01:28

#object[ 0x3a0c97b7 "GqlQuery{type={queryType=null, resultClass=class java.lang.Object}, namespace=null, queryString=SELECT * FROM User WHERE phone = @phone LIMIT @num, allowLiteral=false, namedBindings={allowliterals=Binding{cursor=null, value=StringValue{valueType=STRING, excludeFromIndexes=false, meaning=0, value=True}}, num=Binding{cursor=null, value=StringValue{valueType=STRING, excludeFromIndexes=false, meaning=0, value=1}}, phone=Binding{cursor=null, value=StringValue{valueType=STRING, excludeFromIndexes=false, meaning=0, value=+5512981491039}}}, positionalBindings=[]}"]

Ian Fernandez16:01:05

how can I change this object property,

to true?

Ian Fernandez16:01:09

reflect gives me that allowLiteral is

{:name allowLiteral,
    :type boolean,
    :flags #{:private}}

Ian Fernandez17:01:25

example code in java:

GqlQuery gquery2 = Query.gqlQueryBuilder("SELECT * FROM SomeUnit WHERE key HAS ANCESTOR key(organization,'somename')")

Ian Fernandez17:01:31

(.setAllowLiteral (Query/newGqlQueryBuilder "...") true)


There is no cheshire channel so i am asking here. I added dep [cheshire "5.8.1"] to my projects (uses clojure 9) and i can't cider jack in anymore Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.async.ByteArrayFeeder does anyone know what this is about? I've used cheshire before without problems


@lepistane check the output of lein deps :tree or lein deps :plugin-tree - the cause of an error like that will show up explicitly as a dep conflict there


for example, a dep of cheshire could pull in a library version of jackson that lacks a class that cider needs, usually the fix is explicitly asking for the version of the lib that you need


maybe it's too much to suggest CIDER not use deps that so notoriously break between versions


(or maybe I'm misled and the source of the error has nothing to do with CIDER - the deps tree will expose the source of the issue)


@noisesmith that was some quick help! i appreciate it very much! luckily this time around i saw that ajax lib is using cheshire but lower version so i am just using that and it works now. There was no conflict with deps but i will checkout how i can request that jackson feeder and use latest cheshire


btw this is first time i am seeing 'consider adding these excusions' and there are bunch of deps with that. How bad is this since i am first time looking at this? Should i add all exclusions?


that is what conflicts look like in deps tree, it's saying that these libs ask for different versions and suggesting how to explicitly decide which wins


I usually don't bother until I see a ClassNotFound or similar, those are signs of breakages between versions that mean I need to use the exclusions to manually fix deps


Alright. I will add this to my checklist. Thank you very much

Alex Miller (Clojure team)19:01:27

(fyi, a surprisingly high number of dependency problems relate to jackson :)

truestory 10

yeah, that's my experience also, using just for avoiding jackson starts to seem like a good idea


Any more idiomatic way to do a nested map, e.g. (map (partial map inc) [[1 2] [3 4]]) as (nested-map inc [[1 2] [3 4]])? Not arbitrarily deep, just one deep. Kind of a companion to mapcat


Also anything equivalent to (assoc % :x (get % :x 1)) like (assoc-if-not-set % :x 1)


@jstaab (defn assoc-if-not-set [m k v] (update m k (fnil identity v)))


ah fnil sweet, knew I'd seen something like that before


I've got these log files coming out of a service, and I was going to examine them for some stuff, but they come out with a bunch of gnarly characters. E.g.,

[2m2019-01-08 22:01:17.375[0;39m [32mDEBUG[0;39m [35m624[0;39m [2m---[0;39m [2m[nio-8081-exec-5][0;39m [36mo.n.o.drivers.bolt.request.BoltRequest  [0;39m [2m:[0;39m Request: match (n) return count(n) as nodes with params {}
(wow that looks even worse pasted than it comes out in the repl)


I think those are codes to color code the output


I also think it's.... "us-ascii"?


what's the right way to ignore those characters so I'm just getting the text? I tried feeding in :encode options of "UTF-8" and "us-ascii" to my reader but, same difference

Lennart Buit22:01:53

These are ansi escape codes

Lennart Buit22:01:11

they tell consoles to print in colour indeed


is ansi an encoding that I can feed to the reader?


I bet you could find a regex for deleting them


ansi uses escape codes to control a terminal, it's not something I would want in stored log data

Lennart Buit22:01:33

its not an encoding, they are plain ascii, many terminals just assume that they are ansi escape codes and replace them with whatever is specified


in the clojure ecosystem, you can usually figure out which middleware / extension / utility lib is adding ansi escapes into your log messages and turn it off

Lennart Buit22:01:16

right, do you know which library is logging those, @mathpunk?


no clue, this is a service I don't run. I'm checking with the service owner to see if he knows these are getting logged. It's also entirely possible I'm consuming the wrong thing


I find it more believable that it's just a poorly designed logger that assumes that the only way you look at the messages is by piping them directly to a terminal (where the color codes will actually work)


if your goal is to just read them, using cat should result in color coded text in term


@mathpunk worst case you can use eg. sed to remove the escapes and read normally


I actually want to turn this into data, not just read it.... and that link has a regex for "remove all control sequences" so I'm well on my way. thanks again!


I actually started building a regex to remove them, and then thought, "Wait this might be solved by the right usage of encodings"


so, you've both helped 🙂


this isn't an encoding thing, the escapes are meant to mess directly with a terminal


yeah I get it now


but I guess that was already said :D

Lennart Buit23:01:30

(I feel inclined to reference

Lennart Buit23:01:55

especially the title text had me rolling on the floor first time I read it


it's very good! i might share it with my non-technical hip-hop-loving girlfriend to get her to stare blankly at me 😄