Fork me on GitHub

@mfikes Interesting. Clojure's reverse is just (reduce1 conj () coll) -- I wonder whether Clojure/core would accept a patch to make that use rseq on reversible? collections like ClojureScript does?


Hello, I tried to create lwjgl's video player with opencv. So, I learned some example codes for opencv. Next, I wanted to use lwjgl's library with them. But I got some error messages if I add lwjgl's library into project.clj. Here is the project's path (If you want to see error message, please look at project.clj ) Environment: Manjaro Linux/Leiningen 2.8.1 on Java 1.8.0_162 OpenJDK 64-Bit Server VM Thank you.


How can I get rid of this error?


I don't specifically know how to do this with opencv, but the root of the issue is that the java process doesn't see the relevant opencv native library on its native path


but if you are using a maven lib that interacts with opencv, that should already be set up for you


That's mean... Is there a package in clojars etc? And should I use it?


I wouldn't expect opencv to be on clojars, there's probably something on maven central or nexus though?


I can find some opencv in maven and clojars, so I will try them. Thanks your help!


is there something like javascript’s object-shorthand let obj = {a, b, c} which desugars to let obj = {a: a, b: b, c: c}?


I’m passing around a lot of maps which have shape like {:phone-number phone-number}


it’s somewhat dual to destructuring


@troglotit (let [{:keys [a b c]} {:a 1 :b 2 :c 3}] ..)


oh wait you mean the other way?


no core function which does that, but easy to implement as a macro


oh, yeah, fair enough. Thanks!


in fact, in Clojure you can go one step further: you can generate a map from all the locals


hey that's my gist 😄


I came here to share the same link


haha sorry for robbing you of the satisfaction 😛


(let [x ['a 'b 'c]] (zipmap x x))


;=>{a a, b b, c c}


or (let [x ['a 'b 'c]] (zipmap (map keyword x) x)) if you want them keywords

🙏 4
rich 8

oops, the above should be a smiling face...


you could add and remove emojis clicking on them 😄


Got a problem using a clojurescript cider repl, possibly due to me not understanding exactly how require works in the repl. I want to be able to require some of the namespaces of my project rather than type them out in full for every function call. Up until now I have never needed to do this, switching the repl namespace instead. Now I need functions from several of the project namespaces, and require is just not working for me. To illustrate, here I'm calling a constant defined in anh-front.treeusing (def test-string "hello"):

cljs.user> anh-front.tree/test-string
cljs.user> (require 'anh-front.tree)
----  Exception    ----

  anh-front.tree does not exist

Why does the fully qualified call to anh-front/test-string work fine, but require doesn't? Should it, or am I doing something stupid here?


So that can be quite puzzling, yeah


My theory is that the browser-side compiled artifacts do correctly have the necessary fns. But, for some reason, your local compiler env has 'forgotten' the local context.


Any idea how to remind it?


I sometimes experience a bug (not in cider, but with the figwheel repl in general) where after an initial load, my repl will complain when issuing certain forms. But after I edit my ns and save again, it does a recompile and the local state finally matches the browser's state.


Some errors you get are coming from your local env


some are coming from the remote browser env


so this can confuse you


Your exception above - I believe that's your local env complaining that it doesn't know those things exist, when your remote end clearly does


When issuing a fully qualified fn from the repl to the browser, the local repl compiles that down and assumes there's nothing syntactically wrong. If you pass a non-fully qualified name, the local repl env will attempt to resolve it first and things will break


I get a subtly different error if i try to load the namespace instead of require it:

cljs.user> (load-namespace 'anh-front.tree)
clojure.lang.ExceptionInfo: anh-front.tree does not exist {:cljs.repl/error :invalid-ns}


Assuming figwheel is still watching and compiling in the background, if you edit and save the file, do you see indications of a recompile in the browser? And does the loading then work?


good chance your configuration is tainted somehow


looks like the recompile is happening as normal whenever I change a source file


But the load never works


Woah, stranger and stranger. The original string I defined was (def test-var "hello") and I just called it by the old name by mistake and it gave me an error message and the correct previously defined value!

cljs.user> anh-front.tree/test-var
----  Compiler Warning on   <cljs form>   line:1  column:1  ----

  Use of undeclared Var anh-front.tree/test-var

  1  anh-front.tree/test-var

----  Compiler Warning  ----


right, so your local env 'forgot' about test-var but it still got passed to the browser and the browser returned "hello", is what I think is happening there


You've managed to get your environment into a state where the browser and your local env aren't synchronized.


Sometimes this is the user's fault, sometimes it's bugs in our tools


Trying to keep those two states - local and remote - synchronized in all possible web development workflows is a difficult task


I had a problem where I wanted to query all rows from a table in a database, then generate insert statements to write to a file that I could then take and run on a different database with the same table from the sql file. I am a beginner to clojure and was wondering if anybody could review the way I solved this problem and tell me how to improve it? Or tell me anything weird I’m doing that I could accomplish a much better way


@john I think I have seen this before. Sometimes the first thing I do is call re-frame.db/app-db and get back an error message AND the contents of the app-db. The error message usually goes away once I start editing things. Nothing I do is making the require work though. Maybe I should fire up a different repl, no browser, for this part of the job. Thanks for the assistance, I'm one step closer to having a clue 🙂

👍 4

@john turned out it just needed the :source-paths filling out correctly. Works fine now.


@josmith2016 not sure I fully understand your code, but first thought is wouldn't interpose do a lot of the work for you?


What does interpose do?


puts a separator between entries of a list I think


 [sep coll]
  Returns a lazy seq of the elements of coll separated by sep.
  Returns a stateful transducer when no collection is provided.


Thanks I'll check it out


There's also a last fn you might find useful. I think I heard its pretty much reverse and first under the hood but would make the code more readable.


there's also butlast


@josmith2016 (clojure.string/join "," coll) should do exactly what you want


(let [statement (str "INSERT " (clojure.string/join ", " ["user_id" "user_name"])
                     " into USERS")]
  (prn statement))
"INSERT user_id, user_name into USERS"


Thanks guys! I’ll try all those out


given a hash-map of vectors { :foo [] :bar []} how can I apply map to the vector keyed by :bar only and get back the whole hash-map with an updated :bar?


(update m :bar (fn [v] (map v f))

Alex Miller (Clojure team)17:04:28

shouldn’t that be (map f v) ?


thanks @donaldball @alexmiller just learned about update that's damn handy


i was trying to do it with assoc but was having trouble 😕


@ramblurr see also update-in, assoc-in


hm, after that update/map the vector is now a list


wrapping map in vec would make it a vector again, but is there a better way to do that?


I have a leiningen project with a subproject, how do I add the subproject as a dependency to the parent one, so I can use it as a lein <sub-pro task>?


basically, I’ve followed to create a new generator (which lives as a leiningen project within the parent project), but I’m not sure how to add the subproject to the parent project in order to be able to do the lein generate <thing>


Whoops, I figured it out, I was adding to :dependencies instead of :generators


Is it common practice to have a :type key in clojure maps, with a keyword indicating the “type” of the entity that the map is representing?



{:type :my-app/person
 :name "John Smith"}


I am not just talking about entities that might end up in a database


but also internal stuff


data flowing through an application


also, I think you'll find that many multimethod definitions just dispatch on :type


@joelsanchez yep, I have been doing that a lot and I was wondering if it was “good design” or if I was doing something wrong

Alex Miller (Clojure team)21:04:29

in some cases this is a sign that you could instead use defrecord and dispatch on the type or use protocols


@alexmiller mmh, I see. Do you think it would be frowned upon to have a :type key on most maps in the application then? Or it would depend on the use-case?

Alex Miller (Clojure team)21:04:31

there are a lot of tradeoffs in maps vs records


I find maps to be nicer to work with than records, but that might be my lack of experience with Clojure


As in, I find them more explicit

Alex Miller (Clojure team)21:04:05

I consider both to be idiomatic


@alexmiller thank you 🙂 follow-up question: would it be idiomatic to use the derive function to construct a hierarchy of types?

Alex Miller (Clojure team)21:04:33

yes, although fyi most people aren’t even aware that this exists


are they not aware that it exists because it’s frowned upon to use it? or just because it’s not well known?

Alex Miller (Clojure team)21:04:15

most people don’t really do “hierarchy” type things


The use-case I have is very simple. I want to represent “failures” in my application as maps. A lot of functions can either return some result, or return a “failure” map. There are many types of “failures”, and so I was thinking of deriving them all from a keyword, e.g. :myapp/failure


@U61HA86AG oh wow, thank you! it’s funny; the basics of what you just link are almost exactly what I implemented in my project, but it contains a few extra nice functions


(I am working on a theorem prover, if that puts some context)


hey does anybody actually use schema for type checking? I’m kind of confused that there appear to be terminal code in the output. It suggests that there is some way to get better formatting, but I can’t figure out how.