Fork me on GitHub
#beginners
<
2016-11-28
>
josh_tackett01:11:27

What does (.. ) mean?

josh_tackett01:11:40

used like this:

(.. (getChannel (str "/topic/" channel-name))
+          (subscribe (proxy [ClientSessionChannel$MessageListener] []
+                       (onMessage [channel message]
+                         (do
+                           (println "[[Receieved Message]]" message)
+                           (on-message [channel message])))))))

haywood01:11:51

maybe it's like yada yada

haywood01:11:07

like it could be referring to code like (let [chan ...])

haywood01:11:43

or (defn subscribe-to-chan [chan-name] ...)

Alex Miller (Clojure team)02:11:46

no, .. is a macro that applies a series of Java method calls to an object

Alex Miller (Clojure team)02:11:19

so the getChannel expression returns an object and then the subscribe method is invoked on it

haywood02:11:07

:thumbsup::skin-tone-2: lol, thanks alex TIL

chooie04:11:57

Hey gang, what are my options for passing environment variables to clojurescript? I’m currently using levand/immuconf which is fantastic but I’m pretty stumped on using this on the frontend. I use hiccup to generate my index page - can I somehow pass this info through that?

haywood04:11:34

is making an ajax request on page load for those too dumb of a suggestion

chooie04:11:06

the environment variables would be things like hostname and port so this is not an option

gowder04:11:44

@chooie: if they're set at compile-time you could always take whatever you're using to get them in clj and just send it to cljs in a macro. The general technique demonstrated here (w/ json data and hiccup generated from templates, but easily adapted to environment variables): https://github.com/paultopia/jsonmacrodemo

chooie04:11:38

Thanks @gowder, I’ll check it out

chooie05:11:51

@gowder it’s a good suggestion but the use of calling immuconf/load doesn’t seem to play well with immuconf’s reader literals: java.lang.RuntimeException: No reader function for tag immuconf/override. I’ll have to do some more research into how those literals work. Additionally, a minor gripe is that the macro namespace would have to be recompiled every time a change was made to the config file (admittedly this wouldn’t happen often).

practicalli-johnny11:11:10

Any suggestions for Clojure projects that have issues that could be looked at by someone relatively new to that project ? I'm looking to do as much as I can for Clojure projects in December for http://24pullrequests.com/

bigkahuna12:11:35

That’s a great site and you can enable the ‘beginner friendly’ search flag to find easier projects to contribute to.

roelofw14:11:17

Someone who can help me with this challenge from4clojure :

(= [1 2 [3 4 5] [1 2 3 4 5]] (let [[a b & c :as d] __] [a b c d])) 

roelofw14:11:02

IM thinking of : [a b [c] [d]] but then I see this error message :

Unable to resolve symbol: a in this context, compiling:(NO_SOURCE_PATH:0) 

roelofw15:11:25

What did I wrong here ?

andrii_u15:11:38

if you are asking about what should go instead of __ then it should be [1 2 3 4 5]. which after destructuring and binding will give a=1, b=2, c=[1 2 3] and d=[1 2 3 4 5]

roelofw15:11:00

oke, then I make there my thinking error. I already figured out that a = 1 , b = 2 , c = [1.2.3] and d = [,2,3,4,5]

roelofw16:11:40

I have to solve this challenge : (= false (__ false false)) . So I made this : (fn [& x] (not-any? x ))

roelofw16:11:05

but now I see this error message on 4clojure : Wrong number of args (1) passed to: core$some

roelofw16:11:17

where does some come from. I do not use it

andrii_u16:11:18

problem is in not-any? check its docs to see whats the problem with it

roelofw16:11:01

I think it needs a function so I change it to (fn [ & x] (not-any? true? x)) but now this error message : 'clojure.lang.Cons cannot be cast to clojure.lang.IFn `

roelofw16:11:21

oke, true? is too blame

roelofw16:11:42

I think I need to check some other way if the value is true

andrii_u16:11:11

i don’t know, because it works for me except logic is wrong. but i think you better use and instead of your own function

roelofw16:11:29

and ? I thought that I only could check multiple things with and

roelofw16:11:46

hmm, oke,, then I have to think about another way to solve this

roelofw16:11:37

maybe use some? at some way and and as you both suggested

roelofw16:11:10

I do not find this easy challenges anymore 😞

dpsutton16:11:23

i'm pretty sure you've moved beyond needing to do challenges and need to just make some software

dpsutton16:11:27

just make something

dpsutton16:11:32

don't worry about the challenges

roelofw16:11:09

Im not worried

roelofw16:11:00

I do not feel experiend enough to work at some software like web sites at this point

dpsutton16:11:14

you undoubtedly are

dpsutton16:11:20

do you have a problem you need to solve?

dpsutton16:11:29

that's what you need more than challenges

rauh16:11:50

@roelofw You can also find solutions all over github, in case you're interested in seeing some options

rauh16:11:14

For this one I'd just use distinct and check the result.

roelofw16:11:42

@dpsutton I like to write some financial app which can grow to a some sort of accounting app

dpsutton16:11:15

well make a console based one now

dpsutton16:11:21

then migrate that logic to a webapp

roelofw16:11:55

I could begin with one account and try to make it work that you could deposit and withdraw money from it

rauh16:11:07

Or actually, remember that = and not= take arbitrary # of paramters

roelofw16:11:27

I think I need a atom to hold the actual amount that is on that record

dpsutton16:11:41

my one piece of advice would be to build something you actually want and need to use

roelofw16:11:51

I want to use it because there is no free accounting system which I can use for my volunatry work as a financial person for a toy library

roelofw16:11:15

that is a very small "company" which has no money for a accounting system which is also suitable for persons which are not used and have no knowlegde about accounting

roelofw16:11:27

@dpsutton if I make a console app .I have to make some sort of menu I think

dpsutton16:11:27

well you have a need

dpsutton16:11:50

that's quite a lot to bite off for a first app

dpsutton16:11:58

but you have a real need and people who depend on the solution

dpsutton16:11:04

so its a great first step, if a little large

roelofw16:11:10

oke, but I can make it in very small steps

roelofw16:11:46

first step : 1 acccount, and only withdraw and deposit money on it

roelofw16:11:07

and look if I can hold what amount is on that account

roelofw16:11:55

second step : add second account and try to withdraw on one account and deposit on the other

roelofw17:11:20

@dpsutton does that sounds like a good idea ?

roelofw17:11:36

otherwise I do not have a clue what to build

roelofw17:11:58

maybe another idea is to look if I can rewrite a rails app I have made which reads and displays data from painting from the "Rijksmuseum" in Amsterdam

dpsutton17:11:38

that sounds perfect

dpsutton17:11:41

little less ambitious

dpsutton17:11:46

and you have all of the logic figured out

dpsutton17:11:59

so your time is spent actually doing productive things but focusing on how to to it clojure-y

roelofw17:11:23

the second idea is better ?

roelofw17:11:53

Then I have to figure out how to read from a api and process some json data that I want to display

roelofw17:11:33

I can do it on two ways . read first all the paintings ( some 4700) or read it 10 at the time

roelofw17:11:52

on rails I did it with read everything first and put it into a database

roelofw17:11:11

but I think there could be a "better" more efficient way

sooheon17:11:38

Can anyone make sense of this ArityException I’m getting? https://gist.github.com/sooheon/5cba1df56336d9b7e0b9c779a1f8cab9 I’m taking a 2D vector of maps, where the maps represent points on a graph like {:x 1 :y 2}, and I’m trying to convert this to a single map where everything is keyed by a vector of coordinates, like [0 1]. As you can see, when I call the same code without defining it as a function it works just fine.

sooheon17:11:18

Wow, now that I paste that in I see my mistake. I’m overwriting the definition of the map function with my stupid function variable name… thanks for helping by merely existing, guys :p

roelofw18:11:31

How can I download en use cli-http in repl. I did (require cli-http as client) but then clj-http cannot be found ?

seancorfield18:11:19

It needs to be in your project.clj or build.boot dependencies.

seancorfield18:11:38

Or, if you’re using Boot, you can just specify it on the command line: boot -d clj-http repl

roelofw18:11:40

oke, so first I have to make a project

roelofw18:11:50

I use lein

seancorfield18:11:59

(I know, we’ve had this discussion 🙂 )

seancorfield18:11:42

That is one of the nice things about Boot when you’re just experimenting with libraries, you can start a REPL anywhere with all the dependencies you need, without needing to create a project first 🙂

dpsutton18:11:16

that is a really cool efeature

roelofw18:11:06

What is clJ-http library fast

roelofw18:11:32

I did the same in rails earlier this year and there I had to wait till I saw the data

roelofw18:11:54

Next on my list. Take all the principalOrFirstMaker and the longTitle out for every painting.

roelofw18:11:28

I think I need first to parse it with cheshire

roelofw18:11:58

and I think I can then use a map for getting the data out of the json file

roelofw18:11:52

Stupid beginners question. How can I store the contents of cli-http in a variable in repl?

haywood18:11:21

create a debug atom, and in your code you can reset! the atom with the thing you want to mess with

haywood18:11:33

(that's my backwards way of doing it at least)

roelofw18:11:44

@haywood thanks for the tip

roelofw19:11:49

why here a object as output :

(ns proefopdracht.core
  (require [clj-http.client :as client])
  (require [cheshire.core :refer :all]))

(defn read_numbers
  "Reads the ids of the paintings"
  []
  (-> (client/get  "")
      :body
      parse-string
      (get "artObjects")
      (->> (map #(get % "id")))))



(println read_numbers )  

haywood21:11:40

@roelofw you're not calling it as a function

haywood21:11:55

(println (read_numbers))

haywood21:11:28

just tried in the repl

repl
proefopdracht.core=> (read_numbers)
("nl-SK-A-1718" "nl-SK-A-2963" "nl-SK-C-2" "nl-SK-C-149" "nl-SK-A-3841" "nl-SK-C-1368" "nl-SK-A-1115" "nl-SK-C-216" "nl-SK-C-211" "nl-SK-A-799")

haywood21:11:29

btw, boot -d <package> repl ftw

roelofw21:11:38

Tomorrow work on the second part. With the numbers I can ask for more data on the external api

seancorfield21:11:37

@roelofw You can tell clj-http to parse the result from JSON to Clojure data structures automatically so you don’t need parse-string

seancorfield21:11:15

(client/get “the URL” {:as :json}) I believe… would have to check the docs...

roelofw21:11:20

@seancorfield oke, I have to look that up on the readme

roelofw21:11:23

I think you mean : {:accept :json}) @seancorfield

roelofw21:11:15

nope, when I do :

defn read_numbers
  "Reads the ids of the paintings"
  []
  (-> (client/get  "" {:accept :json})
      :body
      (get "artObjects")
      (->> (map #(get % "id")))))  

roelofw21:11:25

I see a empty seq

roelofw21:11:04

and when I do this :

(defn read_numbers
  "Reads the ids of the paintings"
  []
  (-> (client/get  ""{:as :clojure})
      :body
      (get "artObjects")
      (->> (map #(get % "id")))))



(println (read_numbers))
 

roelofw21:11:35

I see this error : xception in thread "main" java.lang.RuntimeException: Invalid token: :, compiling:(C:\Users\rwobb\Desktop\clojure\proefopdracht\src\proefopdracht\core.clj:15:1)

olslash21:11:30

:as :clojure wont parse json right, you're telling it the endpoint is returning EDN

olslash21:11:12

my guess anyway, its seeing : in the json string

roelofw21:11:48

oke, then I have to use as json

roelofw21:11:48

nope, then I see a empty seq

olslash21:11:59

what if you print after getting artobjects?

roelofw21:11:44

I see nil as answer

roelofw21:11:52

If I do a print after :body I see this as output :

{:elapsedMilliseconds 74, :count 4736, :artObjects [{:principalOrFirstMaker Piero di Cosimo, :webImage {:guid e68b810a-1d70-49e0-a210-5eb7b28a38aa,  

olslash21:11:20

so it looks like your string keys are coerced to keywords

roelofw21:11:24

I print a part because its a big file

olslash21:11:40

-> (get ...) :body :artObjects

roelofw21:11:23

@olslash what do you mean exactly ?

olslash21:11:39

in your example you have (get "artObjects")

olslash21:11:59

but in what you printed, artObjects is a symbol

olslash21:11:11

keyword sorry

roelofw21:11:45

oke, so I can do the same as the body part , just use :artObjects ?

roelofw22:11:29

yep. now hoping that the map part is still working

olslash22:11:07

you'd change that as well since "id" should bea keyword

roelofw22:11:01

hmm, still get a object instead of a map

roelofw22:11:44

I changed the last line to (->> (map #(get % :id))))

jswart22:11:35

(->> (map :id)))

jswart22:11:44

no need for anonymous fn

roelofw22:11:53

nope, still a object

roelofw22:11:20

on this code :

defn read_numbers
  "Reads the ids of the paintings"
  []
  (-> (client/get  ""{:as :json})
      :body
      :artObjects)
      (->> (map :id)))


(println (read_numbers))  

olslash22:11:43

your parens are messed up

olslash22:11:49

:artObjects)

roelofw22:11:31

yep, got it working again

roelofw22:11:59

Everyone thanks, tomorrow time to try to download more data with the help of the numbers I got now

roelofw22:11:39

I need then to use two different urls which used the numbers . I hope I can make it work async somehow

ghadi22:11:05

i tend to avoid double threading -> && ->>

ghadi22:11:25

but if you're going to double thread, inverting the flow reads a slight bit better to me:

(defn read_numbers
  []
  (->> (-> (client/get "" {:as :json})
           :body
           :artObjects)
       (map :id)))

;; better
(defn read_numbers
  []
  (let [art-objects (-> (client/get "" {:as :json})
                        :body
                        :artObjects)]
    (map :id art-objects)))

olslash22:11:59

or use as->

seancorfield22:11:31

Given that you can use either -> or ->> with the keywords to navigate the structure I’d do

(->> (client/get “…” {:as :json})
     :body
     :artObjects
     (map :id))

ghadi22:11:49

personally i find ->> goofy when not dealing with collections

ghadi22:11:04

it happens to work because it shoves the arg into the correct position

jgh22:11:47

What's the difference between -> and ->>?

ghadi22:11:04

ok that is working...

jgh22:11:14

oh it's reversed

ghadi22:11:45

oops that was a bad example

ghadi22:11:41

-> threads the given argument through the "primary position" (the second argument) in each of the forms ->> threads the given argument through the last position in each of the forms

ghadi22:11:05

generally, -> is for scalars, ->> is for collections

ghadi22:11:20

you'll notice the clojure.core library all follows that argumentpattern

jgh22:11:26

so it's kind of a readability macro then?

ghadi22:11:39

collection ops like filter map take the collection at the end

ghadi22:11:12

things like assoc dissoc take the primary argument in second position (assoc the-map ...)

jgh22:11:45

I think I need to get used to the original form before jumping into modifying it with macros heh

roelofw22:11:32

Can I use the same layout when a need to map over all the ids and use them to read another url ?