Fork me on GitHub
Evan Bowling00:03:52

@duminda I would try removing some handlers until you get something working again (albeit less functional while you are debugging)


I've got some maps. I need to sort them so that they're first sorted by gender (females first, then males or non-binary people), and then sorted by last name. Here's my custom comparator, followed by an example I found that sorts strings by length and then alphabetically, followed by my failing attempt to duplicate that logic---


I can kinda see that mine has a different shape but, I'm not sure how to correct it. I'm kinda confused by the sort-by docs


Maybe I need to use sort? But, I'm fuzzy on how composition of comparators works, in any case


This also does not work. Huh.


@mathpunk A couple things. You are trying to mix the arity of :gender and :last-name: (which takes one map, the way you’re using it) and compare-gender which takes two arguments. Could I recommend the following?


Please --- I'm all messed up on arity over here, I can't quite tell how sort-by is applying the fn


if you score the gender as a unary function, it’s very close to what you seem to want.


A fine solution. What I'm having trouble with is, doesn't - have arity 2?


that's what's throwing me about the structure I was trying to adapt


(type (int 10)) returns java.lang.Integer. How do i create a primitive int in clojure?


here - is unary, just negating the score, so you get high-to-low values for gender


OH. See I thought the example function was counting, checking the difference, and getting - or + or 0 that way


@oliv "exit" isn't a clojure thing, it's a thing nrepl does, so if you make your own repl it won't work


@rgorrepati inside a function the compiler can inline calls that use primitives, but that isn't done for type because type isn't declared to take a primitive arg


@rgorrepati if you need to ensure that numerics are inlined, check out *warn-on-boxed* <> Boxed math warnings – Inside Clojure Tales of Developing Clojure


Is there a good tutorial aimed at complete newbs for debugging in clojure and clojurescript? (I mean, it shouldn’t assume familiarity with the language or the environments) I am especially interested in these: 1. debugging cljs code in figwheel repl 2. Debugging compojure ring handlers


Thanks, I will have a look


There's also a debugger you can use in editors like emacs, Intellij, and I suspect others.


(I don't know where good tutorials for those are though).


It's been a few days since I took interest in Clojure, today I dived a bit into control flow and this simple operation brought me so much joy.

(if (nil? nil)
  (do (println "Success!")
      "nil? nil returned true")
  (do (println "Failure!")
      "nil? nil returned false"))
It feels so natural, I haven't experienced this with any other programming language. I'm excited to see what else Clojure brings me! 😄


in the real world you'd probably use if-not there though


Makes sense, thank you @joelsanchez!

Russ Olsen13:03:22

Also keep in mind that nil is falsy, so that plain (if-not nil... will also work. But of course false is also falsy, so it's not quite the same.


Hi all, I need some help with com.rpl.specter. I have this:

(let [data [{:id :a
             :name "A"}
            {:id :b
             :name "B"}
            {:id :c
             :name "C"
             :age 20}]
      ids #{:b :c}]
  (->> data
       (specter/select [specter/ALL (comp ids :id)])
       (specter/transform [specter/ALL] (juxt :name :age))
       (specter/select [specter/ALL specter/ALL some?])))

;; result is ["B" "C" 20]
Basically I need to get the given fields, in this case it's :name and :age, from data whose :id is in ids, place it in a single vector filtering nil values. It works, but can this be improved? Thanks!


@funyako.funyao156 Prob:

(->> data
       (sp/select [sp/ALL (sp/selected? :id ids)
                   (sp/multi-path :name :age)


@funyako.funyao156 (select [ALL (selected? :id #(contains? ids %)) (multi-path (must :name) (must :age))] data)


I was too late


Oh must is probably even better 🙂


the highly scientific benchmarks I just performed in the repl seem to indicate that your version is 2x faster 🙂


Btw is it right that selected? works just like a predicate with selected path but don't actually select the element itself? Maybe the way I'm wording it is a little bit confusing....


@schmee Because of the 2x must or contains??


seems like they contribute about one half each


@funyako.funyao156 yes, that’s how it works


Tried to use insecure HTTP repository without TLS.
This is almost certainly a mistake; however in rare cases where it's
intentional please see `lein help faq` for details.
- How to track the source of this bug?


^ Error from lein


@duminda could we get a little more context? E.g. paste what commands caused the above message.


@eigenhombre: lein ring server-headless proj file:

(defproject npuzzle "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [org.clojure/clojurescript "1.9.908"]
                 [re-frame "0.10.5"]
                 [garden "1.3.2"]
                 [ns-tracker "0.3.0"]
                 [yogthos/config "0.8"]
                 [ "0.1.5"]
                 [metosin/compojure-api "1.1.11"]
                 [org.clojure/data.priority-map "0.0.7"]]

  :plugins [[lein-cljsbuild "1.1.5"]
            [lein-garden "0.2.8"]]

  :ring {:handler npuzzle.handler/app}

  :min-lein-version "2.5.3"

  :source-paths ["src/clj" "script"]

  :clean-targets ^{:protect false} ["resources/public/js/compiled" "target"

  :figwheel {:css-dirs ["resources/public/css"]
             :ring-handler npuzzle.handler/dev-handler}

  :garden {:builds [{:id           "screen"
                     :source-paths ["src/clj"]
                     :stylesheet   npuzzle.css/screen
                     :compiler     {:output-to     "resources/public/css/screen.css"
                                    :pretty-print? true}}]}

  :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}

   {:dependencies [[binaryage/devtools "0.9.4"]
                   [ "0.2.0"]
                   [figwheel-sidecar "0.5.13"]
                   [com.cemerick/piggieback "0.2.2"]
                   [javax.servlet/javax.servlet-api "3.1.0"]]

    :plugins      [[lein-figwheel "0.5.13"]
                   [lein-doo "0.1.8"]
                   [lein-ring "0.12.0"]]}}

   [{:id           "dev"
     :source-paths ["src/cljs"]
     :figwheel     {:on-jsload "npuzzle.core/mount-root"}
     :compiler     {:main                 npuzzle.core
                    :output-to            "resources/public/js/compiled/app.js"
                    :output-dir           "resources/public/js/compiled/out"
                    :asset-path           "js/compiled/out"
                    :source-map-timestamp true
                    :preloads             [devtools.preload
                    :closure-defines      {"re_frame.trace.trace_enabled_QMARK_" true}
                    :external-config      {:devtools/config {:features-to-install :all}}}}

    {:id           "min"
     :source-paths ["src/cljs"]
     :jar true
     :compiler     {:main            npuzzle.core
                    :output-to       "resources/public/js/compiled/app.js"
                    :optimizations   :advanced
                    :closure-defines {goog.DEBUG false}
                    :pretty-print    false}}

    {:id           "test"
     :source-paths ["src/cljs" "test/cljs"]
     :compiler     {:main          npuzzle.runner
                    :output-to     "resources/public/js/compiled/test.js"
                    :output-dir    "resources/public/js/compiled/test/out"
                    :optimizations :none}}]}

  ;:main npuzzle.server
  ;:aot [npuzzle.server]
  :uberjar-name "npuzzle.jar"

  :prep-tasks [["cljsbuild" "once" "min"]["garden" "once"] "compile"])


I had an existing re-frame project and added dependencies from a compojure-api project


@duminda That’s a known issue, you can see the FAQ: (search for “insecure HTTP repository”). I think a lot of people deal with that by downgrading leiningen to an earlier version that wasn’t so strict


Hi everyone I have a little problem with transit-clj. I get a transit string from the client side through a websocket connection. It looks something like this ["^ ","~:message",["^ ","~:user-name","test","^0","test","~:ts",1520012789825]] The transit documentation only shows how to use the this with an input stream. -> Is there way to parse it back to a map without turning it to an inputstream first? This thread on google groups explains the same problem but it's dated back to 2014 without a real solution!topic/transit-format/c_5BuPb1R1A


@ezekills the normal way to use it would be to make an input stream from the string


the string is not intended to be the normal format used by transit in jvm clojure


though if you have enough control of your design, you can get transit to decode instead of generating a string in many cases, which is a good thing


@noisesmith thanks for the quick reply. Ok so best case would be to let transit decode instead of generating a string when receiving it? How exactly is this done?


This is the code I'm working with on the backend


@ezekills: it looks like on-receive is doing some magic - if you are lucky there's a separate (or maybe lower level) thing you can do to get the input directly


or it could be that because of the way websocket messages are parsed, the easiest thing is to get a string, and create an inputstream from that to hand to transit