This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-16
Channels
- # bangalore-clj (8)
- # beginners (78)
- # boot (68)
- # cljs-dev (32)
- # cljsrn (43)
- # clojars (2)
- # clojure (147)
- # clojure-italy (4)
- # clojure-nl (2)
- # clojure-quebec (1)
- # clojure-russia (19)
- # clojure-spec (17)
- # clojure-uk (25)
- # clojurescript (98)
- # clr (2)
- # core-async (14)
- # cursive (5)
- # datascript (1)
- # datomic (23)
- # emacs (4)
- # hoplon (8)
- # jobs (4)
- # kekkonen (1)
- # lein-figwheel (9)
- # off-topic (2)
- # om (2)
- # om-next (9)
- # onyx (4)
- # planck (2)
- # re-frame (14)
- # ring-swagger (3)
- # untangled (18)
hallo 🙂 for anyone still awake, is
the preferred way to parse command line arguments in Clojure? 🙂
@goomba Well, it’s the “default”… I’m not sure whether it’s actually “preferred”.
I maintain it these days so LMK if I can answer questions / help (although I’m just about to go to bed — it’s midnight here).
haha I'll catch up with you tomorrow, and thanks 🙂
@agile_geek that was not a problem at all
@agile_geek: interesting, thanks! Ring is still magic to me but one day I hope to grok its capabilities. I think it is a lower level abstraction than my Python Flask experience so I have difficulty making comparisons to things I already know.
@kyle_schmidt you are right it's a lower level abstraction. I just think of it as something that accepts a request and turns it into a map and takes a map response and turns it into an http response.
Slight simplification but that's it basically
@ashnur (partition 2 coll)
or partition-all
depends
ah no sorry I read it backwards
use (apply concat ...)
js/console.log shows the correct line but it doesn't show the content unless i click for each vector
(flatten '([0 1] [2 3] [4 5]))
will do that too. flatten
flattens everything, not just the first level, so nested vectors will be flattened out too
(mapcat identity '([0 1] [2 3] [4 5]))
will do exactly one level of flattening
or (into [] cat '([0 1] [2 3] [4 5]))
for transducer style :)
contact-edges (distinct (filter
(fn [edge]
(or (in? contacts (first edge))
(in? contacts (nth edge 1))))
edges))
in?
is just something i copied from SO which finds the value in the list with some
edges is a (() () ()) i think that's vector of vectors, but i am not even sure about that anymore, i am reading this now : http://clojure.org/reference/data_structures (i've read it before, but without practice, stuff gets confusing fast)
the order doesn't matter. contacts are just numbers. nodes are just numbers, edges are pairs of numbers, edges are undirected
Cool, then I think you can make it a bit nicer by using the set as a function (which checks for membership):
(contacts (first edge)
for example`
You can also get a sliiiight aesthetic boost by using destructuring in your anonymous fn:
(fn [[x y]] (or....
I prefer using that over first
, second
, or nth
most of the time
how to pick random element of a set if i do not know what elements there are and i do not want to try to retrieve elements that might not be there
you can either shuffle
and take the first
or convert to a sequential collection and take rand-nth
which is better if I would like to have the random element wrapped in a set too? 🙂 so i can do union/diff etc.
Why do I see this error message : `No closing tag found for the tag. In file:/C:/Users/rwobb/Desktop/clojure/paintings2/resources/templates/base.html. `
on this code : https://www.refheap.com/124279
Missing %
here: {% style "/css/style.css" }
Also this line
<img src={{ data.tiles %} />
should end in }}
not %}
(So the error message is telling you exactly what is wrong)
How can I rewrite this to a function and some test.
(defn a-half-truth
"Write a function which takes a variable number of booleans.
Your function should return true if some of the parameters are true,
but not all of the parameters are true. Otherwise your function should return false."
[]
(let [solution (fn s
[& s]
(apply not= s))
(and (= false (solution false false))
(= true (solution true false))
(= false (solution true))
(= true (solution false true false))
(= false (solution true true true))
(= true (solution true true true false)))]))
Is this a good test :
(deftest easy3
(testing "a-half-truth"
(= false (a-half-truth false false))))
You probably want (is (= false (a-half-truth false false)))
You can have as many assertions as you like within a test
Yes, clojure.test is pretty specific in its output
@donaldball : I tested it and this seems to work :
(ns forclojure.core-test
(:require [clojure.test :refer :all]
[forclojure.easy3 :refer :all]))
(deftest easy3
(testing "a-half-truth"
(is (= false (a-half-truth false false)))
(is (= true (a-half-truth true false)))
(is (= false (a-half-truth true)))
(is (= true (a-half-truth false true false)))
(is (= false (a-half-truth true true true)))
(is (= true (a-half-truth true true true false))))
)
now I hope I can figure out how I can make a function that only have a list or a integer as output so I can make tests for that
this does not work.
(defn contain-yourself
"The contains? function checks if a KEY is present in a given collection. This often leads beginner clojurians to
use it incorrectly with numerically indexed collections like vectors and lists."
[]
(identity 4))
with these test
(testing "contain-yourself"
(is (contains? #{4 5 6} contain-yourself)))
@roelofw (contains? #{4 5 6} contain-yourself)
tests if the function contain-yourself
is contained in that set, not the result of calling it.
@seancorfield so I have to use apply
in my function
How can I make it then work that a function is returning 4 or is there another way to test the solution in a test
@seancorfield is it so simple as change contain-yourself
to (contain-yourself)
?
so
(defn contain-yourself
"The contains? function checks if a KEY is present in a given collection. This often leads beginner clojurians to
use it incorrectly with numerically indexed collections like vectors and lists."
[]
(identity 4))
can be tested this way :
(testing "contain-yourself"
(is (contains? #{4 5 6} (contain-yourself))))
Anyone know a good way to turn a multilevel hashmap into a string or JSON and preserve the keywords when deserializing?
nvm got it: clojure.walk/keywordize-keys