Fork me on GitHub
#beginners
<
2018-04-21
>
Jacob02:04:25

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!"))

dpsutton02:04:32

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

dpsutton02:04:47

But the var is still used

Chris Bidler03:04:56

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

dpsutton03:04:26

Ah yes. Reading on mobile :)

soulflyer08:04:21

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

steveh201813:04:56

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

soulflyer14:04:28

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

steveh201814:04:01

Nathan Marz has his own channel here #specter

jrbrodie7713:04:17

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?

mfikes13:04:32

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

jrbrodie7714:04:14

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

jrbrodie7714:04:37

@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.

hlegius23:04:52

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? 🎩

steveh201820:04:48

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

mfikes23:04:44

@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.

mfikes23:04:21

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))

hlegius23:04:23

@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?

mfikes23:04:42

Yes, sorted-maps have different perf characteristics

mfikes23:04:18

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

hlegius23:04:03

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

mfikes23:04:26

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

4
👍 4