This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-05
Channels
- # 100-days-of-code (1)
- # announcements (9)
- # aws (1)
- # beginners (195)
- # braveandtrue (60)
- # calva (3)
- # cider (36)
- # cljs-dev (3)
- # clojure (124)
- # clojure-canada (13)
- # clojure-dev (18)
- # clojure-germany (2)
- # clojure-italy (2)
- # clojure-losangeles (1)
- # clojure-nl (9)
- # clojure-russia (1)
- # clojure-spec (20)
- # clojure-uk (109)
- # clojurescript (49)
- # core-logic (29)
- # cursive (7)
- # datomic (62)
- # defnpodcast (1)
- # devcards (11)
- # docker (3)
- # duct (6)
- # figwheel (13)
- # figwheel-main (57)
- # fulcro (2)
- # graphql (11)
- # hyperfiddle (3)
- # jobs (5)
- # jobs-discuss (9)
- # leiningen (2)
- # lumo (1)
- # off-topic (12)
- # onyx (2)
- # pedestal (1)
- # portkey (2)
- # rdf (1)
- # re-frame (39)
- # reitit (13)
- # remote-jobs (2)
- # rum (5)
- # shadow-cljs (82)
- # tools-deps (48)
- # unrepl (3)
- # vim (12)
- # yada (1)
@troglotit what font is that if you don't mind my asking?
Could anyone recommend a web framework like Flask for me? It just needs to be able to do very basic routing and be easy to use.
@sasha504 Compojure (and Ring) would probably do what you need. With Selmer or Hiccup for generating web pages.
(Clojure doesn't really have "web frameworks" for the most part -- there's a strong preference for composing libraries instead)
I use Luminus for web, and also saw this somewhere recently: https://github.com/coast-framework/coast
I don’t need any rails or Django-esque features. I want to be able to link a function to a path, and be able to read the post data.
then what I linked is definitely overkill
+1 for compojure https://learnxinyminutes.com/docs/compojure/
That seems perfect
Thank you
Is there a nice library like requests to quickly make http requests you would recommend?
you can use [http-kit "2.1.16"] which is already in the compojure example* mentioned above I think
or clj-http
A +1 for clj-http. I didn't know http-kit could be a client as well as a server @coinedtalk?
I guess I need to read the docs better 🙂
Ah, I see, it's an async client library as well as a great server. I'll have to play with that 🙂
I’ve been using http-kit with Ions. As a client when deployed, and as a server in dev.
I like clj-http's built-in JSON handling but I guess that can be handled with http-kit with a call back (that populates the promise).
how do I diff a map? clojure.data.diff
seems to care about the order of the collections
As long as the collections are of the type LazySeq or Vector the order will matter. If the collections are #{} then it will be fine.
I also have maps in my maps, so I'm guessing some recursing thingy would be good, but I was just curious if one exists in clojure or if I have to write it myself
Do you have an example where clojure.data.diff seems to care about the order of key/value pairs in a map? I didn't think that it did.
@andy.fingerhut I also didn't think so! it's kind of funny because this explains some odd behaviour I have in another project. here's an example:
(use 'clojure.data)
(def a {:a 10 :b 20})
(diff a (reverse a))
;; [{:a 10, :b 20} ([:b 20] [:a 10]) nil]
Can someone tell me what’s wrong with my project.clj file. My project isn’t picking up on figwheel https://gist.github.com/titaniumbrella/6fc89a42acece7d2a95ae5b5d0c7fd89
or wait, sorry @andy.fingerhut I now saw that reverse turned it into a seq, wait a minute
nvm @andy.fingerhut, you're absolutely correct. I must be doing something else wrong
hey, i'm currently trying to consume a rest service from clojure which provides a swagger spec. is there any library to assist with that? i'm thinking of generating client methods, records or similar. all the things i can find are about providing rest services, not consuming them. i'd appreciate a pointer...
or maybe the question also makes no sense, because a clojure solution would follow a totally different approach
at first glance this looks pretty much like what i was looking for! will give it a try, thx @U054W022G
there is also swagger-codegen, which generates clients to multiple languages. js & java are supported, clojure not directly.
i have problem with http://www.4clojure.com/problem/65
Can somebody tell me how to use this function? https://github.com/gfredericks/org-editor/blob/master/src/com/gfredericks/org_editor.clj#L53 I can't understand how to use it (especially the writer
parameter)
@stardiviner Do you specifically want to deal with streams? If you just need to put some data on disk, spit
is easier to deal with.
Otherwise, you’ll have to pass in a writer: https://clojuredocs.org/clojure.java.io/writer
@henrik I'm using this library org-editor
which is written by others. I'm confused how to use this function write-file
about what parameter to pass to it? Usually I will will think (org-editor/write-file <data> "
. But the first argument is writer
. In the source code definition, I'm confused where is the data passed in?
that makes it sounds like you are calling list on a single item?
list only returns clojure.lang.List, it wraps the items you pass in into a new list
Now when I do an alert for k in n, I get two alerts. The first alert says LazySeq, and the second alert says (nill)
Clojure 1.9.0
(ins)user=> (def a [1 2])
#'user/a
(ins)user=> a
[1 2]
(ins)user=> (list a)
([1 2])
no, it isn't
When I go to http://localhost:3449/database I get this: clojure.lang.LazySeq@3e67faad
that is what you get if someone calls str on a lazy seq
if you want to see the contents, call pr-str instead of str
calling seq on a lazy-seq just gives you the lazy-seq back again, calling list on it just puts it inside a new list
I want an alert for every k in n, but I am getting two alerts where the first alert has everything and the second alert has nil
then you have two items, one is a collection and the other is nil?
alternatively, if you use vec
instead of list or seq, it will turn it into a vector and those do str nicer than lazy-seq
ins)user=> (def lazy (take 10 (iterate inc 0)))
#'user/lazy
(ins)user=> (str lazy)
"clojure.lang.LazySeq@9ebadac6"
(ins)user=> (pr-str lazy)
"(0 1 2 3 4 5 6 7 8 9)"
(ins)user=> (str (vec lazy))
"[0 1 2 3 4 5 6 7 8 9]"
(ins)user=> (pr-str (vec lazy))
"[0 1 2 3 4 5 6 7 8 9]"
so it's a back end error, they are sending you the string of a lazy-seq (which is useless) instead of the contents
what? there are no characters there
@its.ramzi when you have this level of confusion about what's going on, maybe try breaking the problem down into smaller parts. You can use type
to find out what kind of data you are looking at, then pr-str
to see a repl readable version (if possible), count
to see the size, keys
to see the keys of a hash, etc.
also you can use def or swap! with an atom to make the data accessible in your cljs repl
(which makes exploring the data easier)
And def check this guide out: https://clojure.org/guides/repl/introduction
what does the code that makes the alert look like?
OK, that's not nothing, that's a type
content is a function
OK - it could be that is how the type of String prints
(now that I look closer)
So it's a string, I think. Which means iterating over it just gives you characters.
if the content of the string contains clojure.lang.LazySeqblahblah in it, that's an error on your back end,
you need to ensure the back end is generating the data properly, I suspect it should be json encoding
Now I am getting three alerts. Please look at this code and tell me how I could possibly be getting three alerts.
(defn make-table-from-string [n] (js/alert n) ) (defn change-dom [content] (js/alert (type content)) (-> js/document (.getElementById "some-div") (.-innerHTML) (set! (-> js/document (.getElementById "some-div") (.-value) (str "<h2>Hello</h2>" (make-table-from-string content)))))) (defn ajax-input [id endpoint] [:input {:id id :on-change #(.send goog.net.XhrIo endpoint (fn [event] (change-dom (make-table-from-string (.getResponseText(.-target event)))))) } ] )
What does the browser network tab show for the request response from the GET /database call?
({:id 1, :body "sdf", :created_at #inst "2018-08-31T18:02:00.922340000-00:00"} {:id 5, :body "asdf", :created_at #inst "2018-08-31T18:09:51.403570000-00:00"} {:id 7, :body "bye", :created_at #inst "2018-08-31T18:10:34.583642000-00:00"} {:id 9, :body "vv", :created_at #inst "2018-09-04T14:17:53.290623000-00:00"} {:id 8, :body "What should it say CHris? ", :created_at #inst "2018-08-31T18:11:44.118170000-00:00"})
Well you have make-table-from-strong throwing an alert, and that is called from multiple places
The argument to change-dom has a call to make-table-from-string, and then change-dom also has alert, and then it calls make-table-from-string again, which has alert...
The first alert has all the data, the second alert has null, and the third alert has undefined.
Walk through your code. You know you have 3 calls to alert because of how you’ve written the code. Under what conditions are the arguments to the alert those things? Is that correct? Is it what you expect? Should you even have 3 calls to alert? Is your code maybe incorrect?
A very simple question to answer is: why are there three calls to make-table-from-string? Do you think it should be called multiple times?
also you can combine alerts with the kind of exploration I was describing above: (js/alert (str "type: " (type x) " x: " (pr-str x)))
etc.
The very value of “([] [] [])” is a red flag to me that your backend code/query is likely wrong, but that’s another separate issue
usually the ring wrap-json
middleware is used, and if your query sets the right content-type on the request it just works
I'm using luminus queries.sql file, anyone know what's wrong with this query? SELECT * FROM USERS WHERE ip = (:ip)
updating the ip field works using the same syntax which i think is weird, but when I do this it just gets all of them indiscriminately
@coinedtalk don’t wrap :id with parens
doesn't make a difference
Are you sure the change propagated through? Not sure how luminous works, but depending on how the queries.sql file is loaded changes only within that file may not result in those changes being loaded
Eg., in my own app I need to touch the clj file that includes the sql file for sql changes to be reflected (if I’m resetting the app through the repl)
Safest bet for a sanity check is full restart of the application (down the whole repl)
Yep, you are spot on. I'm having trouble with the DB overall it seems. (migrate) usually doesn't work, and (rollback) entirely breaks the app. I have to close all of it, migrate, and then restart to use it. Thanks
Glad to see it resolved. If you don’t have many migrations, I’d be happy to see if I can tell why they are failing. Send me a DM if you’re interested.
(db/save-message! (assoc params :ip (:remote-addr req)))
(defn home-page [{:keys [params] :as req}]
(layout/render
"home.html"
(merge {:messages (db/get-messages (assoc params :ip (:remote-addr req)))}
(select-keys (:flash req) [:id :errors]))))
its supposed to show only messages (users) for that ip, instead it shows them all (but ip, id, and message data are all successfully read/passed)
:ip is localhost but I added a "user" manually to the DB which has a different one to try and filter it out
what about https://purelyfunctional.tv/ @gold88 ?
Looks intriguing but I'm looking for a partner who is above my skill level to discuss my solutions
@gold88 Not a specific one, no, but folks in this channel sometimes step up and volunteer for 1:1 stuff.
You're in Europe somewhere, based on your TZ? When are you most likely to be trying to learn Clojure -- your day or your evenings?
Right now I'm working a JavaScript job during the day, so my clojure sessions are mostly in the evening
OK, well, I don't might having a couple of people on my 'Starred' list in Slack for DMs about learning Clojure -- and I've got enough bandwidth for one more if you want?

I'm based in California so it's almost 11am for me right now -- your evenings would be my mornings.
I'd be more than happy to take that spot @seancorfield thanks for the offer :)
do you mean file or ns? either way is fine, but it's good practice to be precise
@noisesmith both, ex: src/blog/main.clj is blog.main
the .clj is not part of the ns, it's part of the file name
you could have an ns called main.clj, the file would be eg. src/main/clj.clj
which would be weird, but it would work
so the real answer is no, there is no problem with using that name
with a side note about the difference between file name and ns name
For an app of your own, single segment namespaces are OK. For a library that you expect anyone else to use, multi-segment namespaces mean you're less likely to clash with another library's namespaces.
But, in general, it's probably a good mindset to always use multi-segment namespaces.
I think I am sending back JSON, but when I do type, it still says String. How do I know if I have JSON, and how can I loop through JSON?
is the json automatically parsed on the client side or do you need to call (.parse js/JSON ...)
by hand?
So if I have the cheshire source in my src/my-app/clj folder, and I require it in my handler.clj file, then my cljs file can just call functions from it without having to require it at the top of the cljs file?
you shouldn't be able to use cheshire in the frontend, you also don't need it
you can literally use the parse method on js/JSON as I showed above (or something very similar, it's been a while)
Sweet! I got [object Object],[object Object],[object Object],[object Object],[object Object]
that's what I'd expect the results to look like actually, if you use (.log js/console o)
for those objects I think you'll find all the data inside
Hey ! I'm sorry if this question seems stupid. I'm learning clojure and on the official website there is an exercise where you re implement complement. I don't understand why it's implemented the way it is instead of (defn complement [f] (fn [& args] (not (apply f args))))
Can you point me somewhere I can read more about this ?
there isn't much to read about, varargs have a performance hit, so for core combinators in clojure.core that may be used often as build blocks, for maximal performance it is useful to unroll the low arg count common cases
https://dev.clojure.org/jira/browse/CLJ-731 https://dev.clojure.org/jira/browse/CLJ-1487 https://dev.clojure.org/jira/browse/CLJ-2228 are some related jira issues
Could someone help me with seesaw
I want to update a list box when the list is updated
The list is An atom by the way