Re: Clojure newbie code review
Am Dienstag, 10. September 2013 01:24:10 UTC+2 schrieb Igor Demura: Hi Clojure community, (I tried codereview.stackaxchange.com before, but no responses where) I'm Clojure newbie, and feel very excited about it and functional programming in general. I wrote tiny app (59 lines of code) which renders a directory tree to the terminal, filtering with a regex. I'm sure that my code is not perfect and something could be done much better. I'll appreciate if you could spent sometime to review it: https://github.com/idemura/incub/tree/master/tree. Don't know where to get help with this. (str (reduce #(str %1 %2) coll) can be replaced with clojure.string/join (iterate inc 1) = (rest (range)) may be more clear (alter-var-root #'*read-eval* (constantly false)) = why do you think this is necessary? You can convert the regex string into a pattern once in line 51: (when regex (re-pattern regex)) (assoc m p (conj (m p []) f)) = (update-in m [p] (fnil conj []) f)) In general I would separate the different task: * directory tree walking - tree representation * render tree into line definitions * render tree lines into string * print string -billy -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Clojure newbie code review
Philipp Meier phme...@gmail.com writes: (alter-var-root #'*read-eval* (constantly false)) = why do you think this is necessary? Some versions of the Leiningen `app` template put this in the skeleton initial source file. I assume that’s where this came from. -Marshall -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Clojure newbie code review
Regarding your question about join: The clojure.string namespace contains the join function recommended to you. All functions in the clojure.string namespace, and several other namespaces (see below for a complete list) are part of the Clojure JAR file, and in that sense come at no additional charge over and above that Clojure JAR file size. Whether you regard that Clojure JAR file bloated or not is your judgement call (Clojure 1.5.1 is ~3.5 Mbytes). $ java -cp $HOME/.m2/repository/org/clojure/clojure/1.5.1/clojure-1.5.1.jar clojure.main user= (use 'clojure.pprint) nil user= (clojure.pprint/pprint (sort (map str (all-ns (clojure.core clojure.core.protocols clojure.instant clojure.java.browse clojure.java.io clojure.java.javadoc clojure.java.shell clojure.main clojure.pprint clojure.repl clojure.string clojure.uuid clojure.walk user) nil If you add other libraries with their own separate JAR files, you can look at each one to decide whether you think its size is worth it. Many that are written purely in Clojure tend to be source-code only, and thus quite small. For example, Ring + Compojure + Hiccup JAR files total about 40 Kbytes. Andy On Tue, Sep 10, 2013 at 10:46 AM, Igor Demura ig...@google.com wrote: Thank you Philipp, this is really helpful! Marshall's guess where *read-eval* from is right. I didn't googled what does it mean, just left as-is from the Leiningen template. Talking on replacement to join. For this function I'll link additional library. My question how this works: in C++ world, linker will eliminate all unused symbols (classes in this case?) from output binary. Is the same true for JVM/Clojure world? Will it bloat binary? Why do you recommend update-in instead of assoc? First time I did this, than I saw using assoc in similar situation on ClojureDocs and changed my mind. I see your point about architecture. You suggest to make it more sequential (composition like: (f (g x))), instead of injecting actions like this: (defn action [subaction] ;; subaction is a function to pass control to (do ... (subaction ...))) Thank you again. On Monday, September 9, 2013 4:24:10 PM UTC-7, Igor Demura wrote: Hi Clojure community, (I tried codereview.stackaxchange.com before, but no responses where) I'm Clojure newbie, and feel very excited about it and functional programming in general. I wrote tiny app (59 lines of code) which renders a directory tree to the terminal, filtering with a regex. I'm sure that my code is not perfect and something could be done much better. I'll appreciate if you could spent sometime to review it: https://github.com/* *idemura/incub/tree/master/treehttps://github.com/idemura/incub/tree/master/tree **. Don't know where to get help with this. Igor. -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Clojure newbie code review
Thank you Philipp, this is really helpful! Marshall's guess where *read-eval* from is right. I didn't googled what does it mean, just left as-is from the Leiningen template. Talking on replacement to join. For this function I'll link additional library. My question how this works: in C++ world, linker will eliminate all unused symbols (classes in this case?) from output binary. Is the same true for JVM/Clojure world? Will it bloat binary? Why do you recommend update-in instead of assoc? First time I did this, than I saw using assoc in similar situation on ClojureDocs and changed my mind. I see your point about architecture. You suggest to make it more sequential (composition like: (f (g x))), instead of injecting actions like this: (defn action [subaction] ;; subaction is a function to pass control to (do ... (subaction ...))) Thank you again. On Monday, September 9, 2013 4:24:10 PM UTC-7, Igor Demura wrote: Hi Clojure community, (I tried codereview.stackaxchange.com before, but no responses where) I'm Clojure newbie, and feel very excited about it and functional programming in general. I wrote tiny app (59 lines of code) which renders a directory tree to the terminal, filtering with a regex. I'm sure that my code is not perfect and something could be done much better. I'll appreciate if you could spent sometime to review it: https://github.com/idemura/incub/tree/master/tree. Don't know where to get help with this. Igor. -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Clojure newbie code review
Hi Clojure community, (I tried codereview.stackaxchange.com before, but no responses where) I'm Clojure newbie, and feel very excited about it and functional programming in general. I wrote tiny app (59 lines of code) which renders a directory tree to the terminal, filtering with a regex. I'm sure that my code is not perfect and something could be done much better. I'll appreciate if you could spent sometime to review it: https://github.com/idemura/incub/tree/master/tree. Don't know where to get help with this. Igor. -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups Clojure group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.