code-reviews

2019-08-19T11:41:01.037300Z

It is not working as expected if you have nil as an element in your tree

2019-08-19T11:44:03.038800Z

You can check on each iteration of loop that incoming tree is not nil

(defn my-own-flatten [tree]
  (loop [[h & t :as tr] tree
         result []]
    (cond
      (nil? tr) result
      (coll? h) (recur t (doall (concat result (my-own-flatten h))))
      :else (recur t (doall (concat result [h]))))))

2019-08-19T11:44:09.039Z

something like that

2019-08-19T11:46:33.040800Z

also because you are using coll? it will unwrap and flattenize maps same way as sequences. It is ok if this is intentional, but not the same behavior as flatten from core

tdantas 2019-08-19T16:27:54.041400Z

yeah @delaguardo agree. instead of coll? better to use sequential? right ?

2019-08-19T16:29:46.042Z

yes, sequential? is a better option here

tdantas 2019-08-19T16:30:30.042200Z

thx

tdantas 2019-08-19T16:30:39.042500Z

thx for the nil heads up

tdantas 2019-08-19T16:30:54.042800Z

do you have a better flatten implementation ?

2019-08-19T16:44:22.043400Z

from the top of my head

(defn flatten* [obj]
  (if (sequential? obj)
    (lazy-cat
     (flatten* (first obj))
     (when-let [r (not-empty (rest obj))]
       (flatten* (rest obj))))
    (list obj)))

2019-08-19T16:45:35.044300Z

there is also tree-seq function which should work better in that case

Jakub HolĂ˝ 2019-08-19T19:55:33.044600Z

Chase 2019-08-19T20:13:53.045400Z

for those who don't follow that to the #clojure thread I'll reiterate that I've found exercism very, very helpful in getting over some learning humps.

Chase 2019-08-19T20:14:50.046500Z

So I thank all the mentors and those considering it. It's been so satisfying to solve a problem and see those tests pass. Then also refactoring with mentor advice or I also head to #beginners for more advice.

Chase 2019-08-19T20:15:48.047600Z

Speaking of the tests, that has shown me the benefit of tests in a much more real way and I think that is something I will take with me into my programming career. I know now they can help you build to your solution, not just test solutions after the fact.

Chase 2019-08-19T20:17:36.049800Z

One last bit and I'll leave you be. I also check the community solutions after solving a problem and a couple times my solution has matched exactly the elegant solution that has received the most stars from other users! Besides just learning from all the solutions, that has been such a huge motivator to see as I struggle so hard at programming yet get a little bit of evidence I can do this and come up with elegant solutions at the same time! So yeah, I'm a big fan of exercism. If you can spare the time, us learners are greatly appreciative of the mentorship!

Cora (she/her) 2019-08-19T20:23:15.050800Z

yeah, the community solutions are super helpful. seeing people solve it different ways, with different clojure features, really helps my brain acclimate to different ways of thinking

2019-08-19T20:24:30.052200Z

you've probably heard of http://4clojure.com - but that's worth looking at if not

Chase 2019-08-19T20:24:51.052900Z

right?! It exposes you to real world usage of all the cool core functions of Clojure and I think it sinks in better because you've just solved that problem yourself so it's easier to understand these new function uses imo.

2019-08-19T20:24:51.053Z

(it is stuck on an old clojure version, but there's a lot to learn from)

Chase 2019-08-19T20:40:35.054100Z

i'm a fan of 4clojure too for sure! case in point, I just solved a problem on there and low and behold my solution matched how @mfikes solved it and he is one of my clojure idols. I also see 3 other great ways to solve it. I love it!

2019-08-19T20:44:03.055Z

I bet exercism has less code-golf answers (writing bad code just to get a smaller character count)

2019-08-19T20:45:34.055100Z

to my eye the if and the when-let are doing the same thing, and one could be removed(?)

Chase 2019-08-19T20:52:22.056Z

are you on there @noisesmith? I'll follow you to compare with your answers. You frequently help me a lot on the beginner channel. Any others you recommend to follow?

Chase 2019-08-19T20:53:39.056200Z

found you!

Chase 2019-08-19T20:54:12.056600Z

you still have 12 more solutions to go buddy! get to it! lol, just kidding, just kidding.

2019-08-19T20:57:16.057100Z

haha, I haven't updated anything in a while, and those last problems are the hard ones :D