Fork me on GitHub
#beginners
<
2018-03-02
>
Evan Bowling00:03:52

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

mathpunk00:03:39

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

mathpunk00:03:40

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

mathpunk00:03:42

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

mathpunk00:03:13

This also does not work. Huh.

eigenhombre00:03:24

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

mathpunk00:03:02

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

eigenhombre00:03:34

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

mathpunk00:03:08

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

mathpunk00:03:30

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

rgorrepati00:03:36

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

eigenhombre00:03:23

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

mathpunk00:03:46

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

noisesmith01:03:10

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

noisesmith01:03:59

@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

noisesmith01:03:47

@rgorrepati if you need to ensure that numerics are inlined, check out `*warn-on-boxed*` <http://insideclojure.org/2014/12/15/warn-on-boxed/> Boxed math warnings – Inside Clojure Tales of Developing Clojure

nakiya01:03:11

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

nakiya03:03:56

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

andlrb12:03:31

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! 😄

joelsanchez12:03:54

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

andlrb12:03:06

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.

fmn13:03:13

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!

rauh13:03:21

@funyako.funyao156 Prob:

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

schmee13:03:24

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

schmee13:03:32

I was too late

rauh13:03:54

Oh must is probably even better 🙂

schmee13:03:47

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

fmn14:03:24

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

rauh14:03:51

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

schmee14:03:11

seems like they contribute about one half each

schmee14:03:30

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

nakiya15:03:25

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

nakiya15:03:44

^ Error from lein

eigenhombre15:03:52

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

nakiya16:03:42

@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"]
[day8.re-frame/http-fx "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"
"test/js"
"resources/public/css"]

: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]}

:profiles
{:dev
{:dependencies [[binaryage/devtools "0.9.4"]
[day8.re-frame/re-frame-10x "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"]]}}

:cljsbuild
{:builds
[{:id           "dev"
:source-paths ["src/cljs"]
: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
: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"
: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"])

``````

nakiya16:03:50

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

manutter5116:03:31

@duminda That’s a known issue, you can see the FAQ: https://github.com/technomancy/leiningen/blob/master/doc/FAQ.md (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

ezeclo18:03:21

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. -> https://github.com/cognitect/transit-clj#usage 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 https://groups.google.com/forum/#!topic/transit-format/c_5BuPb1R1A

noisesmith18:03:46

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

noisesmith18:03:07

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

noisesmith18:03:36

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

ezeclo20:03:22

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

ezeclo20:03:07

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

noisesmith20:03:52

@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

noisesmith20:03:19

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