Fork me on GitHub

Hey guys im starting some clojurescript and im trying to run my repl but I keep getting an error from my routs I created Im getting an error on my Post and created a project using luminus.

(defn signup-page-submit [user]
  #_(let [errors (signup/validate-signup user)]
    (if (empty? errors)
      (response/redirect "/signup-success")
      (layout/render "signup.html" (assoc user :errors errors)))))

(defroutes home-routes
  (GET  "/"               []       (home-page))
  (GET  "/about"          []       (about-page))
  (GET  "/signup"         []       (signup-page))
  (POST "/signup"         [& form] (signup-page-submit form))
  (GET  "/signup-success" [] "success!"))


You call the signing page submit with a sequence (& form) but that function seems to be expecting a user. Further, that function seems to have the let binding for errors commented out


But the var is still used


wouldn’t that #_ comment out _the whole of the fn body_?


Ah yes. Reading on mobile :)


I'm building a tree and each node contains children which is either a map of other nodes or a vector of strings. To handle these different things I'm trying to check for the type of children using code like this:

(if (= cljs.core/PersistentArrayMap (type ch))
                   (for [child ch]
                     (node tree (conj path (key child))) )
                   (for [child ch]
                     [:li (str child)]))
turns out sometimes the type is not PersistentArrayMap but PersistentHashMap so this fails some of the time. I have flipped it round to check for PersistentVector instead and that works, but I can't help thinking there must be a better way to check for the difference between a vector and a map


Also, you may want look into using specter for traversals and transformation on the tree.


Checking it out now, looks like it could be very useful. Thanks @UA2UNSUGZ


Nathan Marz has his own channel here #specter


Any tips for making chaining of go blocks less verbose? I’m trying to list an s3 bucket, then open a file, then parse. Annoying to put it all in one function, also annoying to have to wrap each in a go block and take for each. Ideas?


@jrbrodie77 Hmm. You should be able to use a single go that wraps several takes


I can but this makes debugging difficult, I’d rather split the work into 3 or 4 funcs


@mfikes I suppose I just need a few more helpers to help me debug (like a pass thru print). I can also imagine macros helping but I’ve been avoiding them so far.


Hello there! I’m studying maps in Clojure and would like to dissoc some elements from a map Considering:

(def elements [:c :d :e :f :g :h :z])
(def dict {:a 10 :b 20 :c 30 :d 40 :e 50 :f 40 :g 59 :z 8934 :m 894 :n "jhiouae"})
I came up with the solution using apply. Fine, but it changed map ordering. So, I tried to push it back into a ordered hashmap:
(into {} (sort (apply dissoc dict elements)))
It worked, but I needed to convert into hash after sorting. Is there a way more simpler/elegant to solve this kind of issue? 🎩


Take a look at specter. You won't have to worry about reconstructing the structure you started with.


@hlegius The order doesn't exist even in dict. But you can make a sorted map instead and if you dissoc from that the result will still be sorted.


So, try starting off with (def dict (sorted-map :a 10 :b 20 :c 30 :d 40 :e 50 :f 40 :g 59 :z 8934 :m 894 :n "jhiouae")) or, alternatively, end up with (into (sorted-map) (apply dissoc dict elements))


@mfikes whoa! I didn’t notice that! I ran dict into repl and saw haha! Got it! So, using sorted-map I will have a small performance penalty adding, traversing, etc, right?


Yes, sorted-maps have different perf characteristics


As an aside, your final answer looked sorted only because it was small enough to end up being implemented as a PersistentArrayMap which happened to retain the order produced by sort


hmm, interesting. Clojure chooses the better building strategy based on size, then. Great to know! Thanks for all explanation @mfikes 🎩


Exactly, in ClojureScript you can see this boundary via (.-HASHMAP-THRESHOLD PersistentArrayMap), which is 8

👍 1