6

There are a few minor improvements you can make here that lead to a fairly elegant implementation. First, using flatten is rarely a good idea, because rather than just dealing with the top-level structure of the thing you hand it, it reaches down into its inner structure, thus making it brittle when you change the representation of your data. Therefore, you ...


5

Naming and interface Please avoid mixing English (calculate-distance) with Portuguese (raio). The code should be in English; write your comments in whatever language you prefer. ltd and lgt seem like awkward abbreviations; lat and lon or lat and lng seem more conventional. The latter is what Google uses for the Maps and Android APIs, for example. ...


4

First up, notice that you're creating 3 leted names by using exactly the same expression but replacing one key lookup function. This is a prime candidate for deduplication by making a local function. (defn my-filter [str-input] (let [seek (fn [k](filter #(re-find (->> (str str-input) (upper-case) ...


3

I don't have any performance related suggestions unfortunately. I do have a couple cleanup suggestions though. The bounds checking function can be cleaned up a bit by making use of "comparison chaining" similar to what you'd use in Pytbon: (defn within-bounds? [[row col] width height] (and (< -1 row width) (< -1 col height))) In the ...


3

You are right to want to avoid creating the nested structure to begin with. I imagine you read my answer in the question you linked (the second one). As there, here the solution is to use mapcat instead of map. And as I also say in the comments there, while mapcat-indexed does not exist, you can just pass an extra (range) argument to get numbering. (defn ...


3

Very nice work! My only suggestions are to split your large-ish function into several smaller, simpler pieces, and to give each of those pieces its own docstring: (require '[clojure.string :as str]) (def month-names "A vector of abbreviations for the twelve months, in order." ["Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"]) (...


2

The dorun/for combo is excessive. When carrying out side effects over a list, use doseq: (doseq [x (range (.round js/Math (/ (q/width) grid-size)))] (q/line (+ grid-offset-x-mod (* x grid-size)) 0 (+ grid-offset-x-mod (* x grid-size)) (q/height)) (draw-number :horiz x grid-offset-x grid-offset-y)) That allows you to shorten the first line by a bit, and ...


2

Generation suggests cartesian product which suggests for comprehension: (def ranks [1 2 3 4 5 6 7 8 9 10 11 12 13]) (def suits [:spade :heart :diamond :club]) (defn x-1 [] (let [counter (atom -1)] (for [rank ranks suit suits] {:rank rank :suit suit :card-id (swap! counter inc)}))) I'm leaving the (atom -1) as an alternative to @Sam ...


2

Depending on your final goal, you may be interested in the Tupelo Forest library. Here is a sample of what you can do (data converted to the "tree" format): (dotest-focus (with-forest (new-forest) (let [data {:tag "program" :state "here" ::tf/kids [{:topic "Books" ...


2

Unfortunately, I've never used spec, reframe or clojurescript before, but I can note general Clojure things that can be fixed up. filter-people has far too much nesting. Having code like you do affects readability (you need to read it bottom-up instead of top-down like you would most code), and makes it harder to add to (as you'll need to need adjust ...


1

First, fixing a few of the errors that I noted in the comments and altering the formatting a bit, I have: (defn invert-number [n] (+ 1 (* -1 n))) (defn number-complement [num] (let [numstr (.toString num 2) bits (map (comp invert-number js/parseInt) numstr) complement-bits (reduce str bits)] (js/parseInt complement-bits 2))) (println (...


1

I don't really see anything major. I also don't know Cljs (only Clj), so I apologize if a suggestion of mine doesn't apply to Cljs. Just a few small things: Personally, I don't like having function definitions all on one line. Increasingly, I'm even splitting def definitions over two lines. I find it generally helps readability. I'd change your definitions ...


1

I happen to have written a distance calculator in Clojure so I am going to show you my code. I'm sorry that it doesn't have answers to all your questions, but I will try to give you some comments, as well. I haven't used spec, so I can't say anything about it. (ns mic-project.distance-calculator) (defn ^:private degree->radian [angle] (/ angle 57.2958)...


1

Sorry the late reply, Below is a lispy-er way to get to the same result :) The main thing is to define a way to get from 2 ul's to a single ul. (so we can use that as a step in a reduce) basically what we want is, given two ul, to append the one of them to the last item of the other. The algorithm would be something like this take the last li from the ...


1

I like Sam Estep's answer, and you should implement their suggestions. Another thing you can do, to make things even clearer, is to make parse-iso-date return a map: (defn- parse-iso-date "Returns a map with keys :year, :month, and :day from the given ISO 8601 date string." [date] (zipmap [:year :month :day] (map js/parseInt (str/split date #"-0?")))) ...


1

Looks great! Some minor suggestions; pull the parsed-url aset into a doto, and that naming the request req isn't very useful. Prefer dash to underscore. (let [parsed-url (doto (.parse url url_str) (aset "method" "POST"))] (doto (.request http parsed-url cb) (.write data) (.end)))


Only top voted, non community-wiki answers of a minimum length are eligible