Fork me on GitHub
#beginners
<
2016-12-16
>
unbalanced07:12:01

hallo 🙂 for anyone still awake, is the preferred way to parse command line arguments in Clojure? 🙂

seancorfield08:12:21

@goomba Well, it’s the “default”… I’m not sure whether it’s actually “preferred”.

seancorfield08:12:55

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

unbalanced08:12:25

haha I'll catch up with you tomorrow, and thanks 🙂

roelofw09:12:01

@agile_geek that was not a problem at all

roelofw09:12:15

but thanks for the long answer

kyle_schmidt09:12:35

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

agile_geek09:12:16

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

agile_geek09:12:31

Slight simplification but that's it basically

ashnur14:12:01

how do I get from ([0 1] [2 3] [4 5]) (0 1 2 3 4 5)?

ashnur14:12:32

besides reduce 🙂

val_waeselynck14:12:45

@ashnur (partition 2 coll)

val_waeselynck14:12:50

or partition-all

ashnur14:12:06

checking, thanks

val_waeselynck14:12:14

ah no sorry I read it backwards

val_waeselynck14:12:27

use (apply concat ...)

ashnur14:12:56

yeah, i was just about to say that i want the reverse of partition 🙂

ashnur14:12:52

is there a way for (pprint) to show the original location of where it was used?

ashnur14:12:30

google is useless again for me in this question..

ashnur14:12:54

js/console.log shows the correct line but it doesn't show the content unless i click for each vector

danmidwood15:12:29

(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

alexmiller15:12:43

(mapcat identity '([0 1] [2 3] [4 5])) will do exactly one level of flattening

alexmiller15:12:03

or (into [] cat '([0 1] [2 3] [4 5])) for transducer style :)

ashnur15:12:05

what to use instead of list if I want to check for value?

ashnur15:12:47

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

curlyfry16:12:40

@ashnur Is something not working in your example? What is edges?

ashnur16:12:55

it's working, i just think it's nasty

ashnur16:12:43

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)

curlyfry16:12:07

Also, what is contacts? A list of what you have seen so far?

curlyfry16:12:59

Does the order of contacts matter? Otherwise, I think you may want a set: #{}

ashnur16:12:56

the order doesn't matter. contacts are just numbers. nodes are just numbers, edges are pairs of numbers, edges are undirected

curlyfry16:12:32

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`

curlyfry16:12:47

Instead of your (in? contacts (first edge)

ashnur16:12:37

will try it

curlyfry16:12:23

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

ashnur16:12:06

yes, i think that's way nicer too

ashnur17:12:03

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

alexmiller17:12:14

you can either shuffle and take the first

alexmiller17:12:45

or convert to a sequential collection and take rand-nth

ashnur17:12:25

which is better if I would like to have the random element wrapped in a set too? 🙂 so i can do union/diff etc.

ashnur17:12:49

or i shouldn't care, either is good?

roelofw18:12:17

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

seancorfield18:12:58

Missing % here: {% style "/css/style.css" }

seancorfield18:12:42

Also this line

<img src={{ data.tiles  %} />
should end in }} not %}

seancorfield18:12:32

(So the error message is telling you exactly what is wrong)

roelofw18:12:22

and yes, it telling me what is wrong not where

roelofw18:12:48

first part of a new layout for my site ready

roelofw19:12:12

a 4 clojure question:

roelofw19:12:39

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

roelofw19:12:00

I tried this way to solve 4 clojure challenges but this do not work for me

roelofw19:12:39

Is this a good test :

(deftest easy3
  (testing "a-half-truth"
    (= false (a-half-truth false false))))  

roelofw19:12:22

and can I test more then 1 thing or must I write all the test in seperate functions

donaldball19:12:38

You probably want (is (= false (a-half-truth false false)))

donaldball19:12:58

You can have as many assertions as you like within a test

roelofw19:12:43

oke, and can I then also see if I have many assertions which one is failing ?

donaldball20:12:47

Yes, clojure.test is pretty specific in its output

roelofw20:12:29

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

  ) 

roelofw20:12:15

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

roelofw20:12:56

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

roelofw20:12:24

with these test

(testing "contain-yourself"
    (is (contains? #{4 5 6} contain-yourself)))  

roelofw20:12:47

how can I make a function which output is 4 here so the test will be green

jjfine20:12:33

have you tried using the function in the REPL?

seancorfield20:12:12

@roelofw (contains? #{4 5 6} contain-yourself) tests if the function contain-yourself is contained in that set, not the result of calling it.

roelofw20:12:54

@seancorfield so I have to use apply in my function

roelofw20:12:52

no, that does not work

roelofw20:12:12

Lets go back to the basics :

roelofw20:12:46

I have this test : (contains? #{4 5 6} _ )

roelofw20:12:56

I know the answer is 4

roelofw20:12:38

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

roelofw21:12:53

@seancorfield is it so simple as change contain-yourself to (contain-yourself) ?

roelofw21:12:33

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

roelofw21:12:58

can be tested this way :

(testing "contain-yourself"
    (is (contains? #{4 5 6} (contain-yourself)))) 

josh_tackett21:12:58

Anyone know a good way to turn a multilevel hashmap into a string or JSON and preserve the keywords when deserializing?

josh_tackett21:12:26

nvm got it: clojure.walk/keywordize-keys