Fork me on GitHub
#beginners
<
2015-12-03
>
dbstandsfor05:12:01

hmmm. when I tried running just the loop in the repl (with lst def'd to '(1 2 3 4) in the initial state) it does not resolve. just hangs forever. so I must have something silly somewhere in there...

andrut06:12:18

your recur should take 2 parameters: final and lst, now it's something odd simple_smile you probably meant (recur (conj final even) rest)

dbstandsfor06:12:50

oh, yes. how silly. let me see if it works when I fix that

dbstandsfor06:12:02

yes! That was it. Now the only issue is that into is making a list that's backwards. but I can figure that out.

dbstandsfor06:12:33

thanks @andrut

trancehime06:12:36

Anyone still around?

roelof06:12:01

me , myself and I simple_smile

roelof06:12:38

Im trying to find out where this error message is coming from : CompilerException java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Long,

trancehime06:12:23

contains? is a misleading thing for what i want to ask about

roelof06:12:19

I know, also bitten by the 4clojure exercise ?

trancehime06:12:37

Nah, I'm not doing exercises, I'm working on an app

roelof06:12:20

I know on 4clojure there is a exercise which bites almost everyone

roelof06:12:39

but you are right, contains? is a misleading name

roelof06:12:05

I better could be named for example contains-key ?

trancehime06:12:01

since I am trying to look up something in a vector of maps

trancehime06:12:10

contains? actually accepts the index -_-

trancehime06:12:29

otherwise, for maps, yes, it searches for the key. -.-;

roelof06:12:36

I know now. but the fact you named is searches a index except for maps bites a lot of people

roelof06:12:55

what for app are you making then ?

trancehime06:12:21

eh, it's for work, so I can't really talk specifics, but I can make analogies

trancehime07:12:08

anyway for the meantime I am just trying to check a vector of data like this: [{:id 1 :data stuff} {:id 2 :data more-stuff} {:id 3 :data even-more-stuff}]

trancehime07:12:24

I am thinking of using some but I am not sure how I should write the predicate if I want to check if the map containing :id value exist

roelof07:12:47

sorry . I did not work a lot with some

andrut07:12:07

@trancehime: try this one:

(some #(= (:id %) 1) [{:id 1 :data "stuff"} {:id 2 :data "more-stuff"} {:id 3 :data "even-more-stuff"}])

trancehime07:12:39

and if in your snippet it had #(= (:id %) 4) then that would return... nil correct?

roelof07:12:25

"/ " wishes clojure says where the actual error is and not in the calling function. This way I makes a lot difficult to find the culprit

andrut07:12:23

correct, it will be nil then

roelof07:12:12

What is the best way to find out where this error : CompilerException java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Long,

roelof07:12:28

the error messsage mentions only the calling function

seancorfield07:12:24

That nearly always means that you have an integer and you're trying to invoke a sequence function on it.

roelof07:12:09

found it args is a integer and apply thought it needed to be a function,. So I deleted the apply and everything works well

trancehime07:12:36

I keep getting some thing with Reactive deref not supported in seq even though I am wrapping with doall

roelof08:12:55

@trancehime: I think someone can help you if we can see the code

trancehime08:12:11

it's fine, I'm going to try a different approach

roelof08:12:49

also a possibility

roelof08:12:58

success with your project

trancehime08:12:34

hmm, that didn't work...

trancehime08:12:52

The problem is I'm using 2 reagent atoms to compare -_-

roelof09:12:00

@trancehime: have you already look at this stackoverflow question : https://github.com/reagent-project/reagent/issues/18

trancehime09:12:01

thats where i checked if my doall was supposed to behave properly or not

trancehime09:12:03

but it doesn't

trancehime09:12:38

(if (doall (some #(= (:schedule_id %) (schedule "id")) @user-schedules)) "X" "Y") I'm trying to do this

trancehime09:12:22

i'm baffled because I can display content of everything just fine

trancehime09:12:45

I just want to hide some aspect of the page dependent on whether a certain (schedule "id") is present in @user-schedules

trancehime10:12:49

OK, I figured out the problem.

trancehime10:12:30

Turns out the information from the atoms was never actually being passed into the function.

trancehime10:12:04

I've actually instantiated the information now and contains? on the info behaves as intended, now to implement the checking properly

trancehime11:12:29

Alright so now my next problem

trancehime11:12:25

How do I grab an element in the form of a map {:key1 val1 :key2 val2} when I know val1

trancehime11:12:36

assuming that element is in a vector []

ordnungswidrig13:12:31

trancehime: „grab“ an element?

trancehime13:12:48

OK, for example

trancehime13:12:08

I have this vector: [{:key1 val1 :key2 val2} {:key1 val3 :key2 val4}]

trancehime13:12:26

How do I get {:key1 val1 :key2 val2} knowing :key1 val1

ordnungswidrig13:12:39

(some (fn [x] (some #{val1} (vals x))) [{:key1 val1 :key2 val2} {:key1 val3 :key2 val4}]

trancehime13:12:00

repeated some calls?

trancehime13:12:24

One of these days I should look more in-depth into some and contains? because really the latter's behavior confuses me as a beginner

snowell13:12:33

@trancehime (filter #(= (get % :key1) val1) myVec)

trancehime13:12:04

>Returns a lazy sequence of the items in coll for which (pred item) returns true. welp

trancehime13:12:26

now i feel dumb

snowell13:12:37

We’ve all been there 😉

snowell13:12:54

I’ve been doing clojure for a while now and I still manage to feel dumb at least once a day

trancehime13:12:34

I started learning it recently, my supervisor at work said "you should use clojure to do this assignment since it will get the job done fast"

trancehime13:12:57

'lo and behold, I did actually get a metric ton of stuff done with Clojure

snowell13:12:09

Yeah, the real problem is convincing management 😕

snowell13:12:29

Getting things done quickly is easy!

snowell13:12:04

Equally useful as filter is remove, FYI

trancehime13:12:56

for which (pred item) returns false ?

roelof18:12:29

@trancehime: good that your problems are solved

pvinis19:12:03

what does the ‘#’ mean in `(def

pvinis19:12:53

is it just part of the name?

snowell20:12:34

@pvinis: Yes, in that case

noonian20:12:35

pvinis: in normal code it would just be part of the name. But, if a symbol like that appears inside a syntax quote then it is an “automatic gensym”, meaning the symbols will be replaced with gensyms like columns__G1023 or something.

snowell20:12:01

It’s allowable, if really bad form, to have a # in the symbol name

noonian20:12:36

but you’ll see it a lot in macro definitions

roelof20:12:36

If I have two seperate things in a function. How can I take care that both are executed

roelof20:12:46

like updating a atom and a map

noonian20:12:11

You usually only want a function to have to care about the value it returns

pvinis20:12:11

ok so im trying go model a card game, and wanna generate the deck. i have this (map (fn [n] (suit-card :hearts n)) (range 1 14))

pvinis20:12:18

which generates all hearts

pvinis20:12:42

i tried to do this (map (fn [s] (map (fn [n] (suit-card s n)) (range 1 14)))) but i get a fn back

pvinis20:12:50

so i guess map in map is a bit weird?

roelof20:12:11

@noonian: so I can make to make 2 seperate functions . one for updating the atom and another one for the transactions

beppu23:12:43

@pvinis: Are you trying to do this?

(map (fn [s] (map (fn [n] (suit-card s n)) (range 1 14))) [:spades :hearts :diamonds :clubs])

pvinis23:12:16

yes.. i was missing the suits vector..

Tim23:12:19

if I have ’+, how could I call (apply '+ 32 32) on it?

Tim23:12:45

so that I return 64 like normal?