This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-13
Channels
- # aleph (1)
- # beginners (105)
- # boot (6)
- # cider (9)
- # cljs-dev (61)
- # cljsrn (59)
- # clojure (132)
- # clojure-germany (1)
- # clojure-italy (6)
- # clojure-russia (18)
- # clojure-spec (1)
- # clojure-uk (58)
- # clojurescript (56)
- # core-async (1)
- # cursive (17)
- # datomic (20)
- # docs (1)
- # duct (5)
- # editors (1)
- # emacs (7)
- # events (2)
- # figwheel (7)
- # fulcro (30)
- # graphql (8)
- # jobs (3)
- # leiningen (23)
- # luminus (14)
- # mount (6)
- # off-topic (41)
- # onyx (14)
- # protorepl (2)
- # re-frame (7)
- # reagent (32)
- # shadow-cljs (236)
- # tools-deps (92)
- # unrepl (8)
- # vim (60)
- # yada (1)
@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 ) https://github.com/MokkeMeguru/clj-lwjgl-vplayer Environment: Manjaro Linux/Leiningen 2.8.1 on Java 1.8.0_162 OpenJDK 64-Bit Server VM Thank you.
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
I wouldn't expect opencv to be on clojars, there's probably something on maven central or nexus though?
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}
@troglotit (let [{:keys [a b c]} {:a 1 :b 2 :c 3}] ..)
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
oops, the above should be a smiling face...
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.tree
using (def test-string "hello")
:
cljs.user> anh-front.tree/test-string
"hello"
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?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.
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.
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?
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 ----
"hello"
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.
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 🙂
@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?
cljs.core/interpose
[sep]
[sep coll]
Returns a lazy seq of the elements of coll separated by sep.
Returns a stateful transducer when no collection is provided.
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.
@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"
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))
shouldn’t that be (map f v) ?
thanks @donaldball @alexmiller just learned about update
that's damn handy
@ramblurr see also update-in, assoc-in
wrapping map
in vec
would make it a vector again, but is there a better way to do that?
on context
but you can use mapv
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 https://github.com/weavejester/lein-generate 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>
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?
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
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?
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
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?
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?
just not well known
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