Fork me on GitHub
#beginners
<
2017-01-03
>
seancorfield00:01:29

You can't -> into an anonymous function like that. But you could use as-> instead.

seancorfield00:01:27

(-> {:base-url โ€œโ€}
      (as-> hash-map (assoc hash-map :abs-url (str (:base-url hash-map) โ€œtest2โ€))))

jgh02:01:11

figured out how to make a recursive function that emits a result, it's like a whole new world

jgh02:01:33

most of the examples are like "print the fibonacci sequence". Thanks, I'll just use google.

pwalsh06:01:37

@notanon interestingly, I just saw this in #clojure - import-vars is exactly what I mean.

notanon06:01:40

@pwalsh if your project is the size of an entire programming language + batteries included standard library, i'd agree, splitting up your ns might be acceptable ๐Ÿ˜› ๐Ÿ˜›

notanon06:01:09

honestly though... looking at how clojure.core does it... it's not as if it's very complicated/hacky. up to you ๐Ÿ™‚

notanon06:01:40

you're looking at the unbelievable power of lisp's never ending eval < - > apply loop.

notanon06:01:59

it's up to you how you organize your code. how you feed strings into eval is up to you.

notanon06:01:26

you arent limited by the language (like java with classes)

notanon06:01:39

or dependent on the language to support it (like c# with multi-file classes)

notanon07:01:59

slightly off topic, but i remember watching a presentation from a guy that writes clojure for oil-mining machinery. he just (load ...)'s code from a http url to update the programs in place. just so awesome. and nasa debugging some c++ code on an orbiting satellite via a freakin lisp space repl lol.

sb10:01:35

@notanon (for [x test] {((wcar* (car/get x)) :username) (wcar* (car/get x))})

sb10:01:53

I got this ({"admin" {:username "admin", :password "pass", :roles #{:slckfu.handler/admin}}} {"admin2" {:username "admin2", :password "pass", :roles #{:slckfu.handler/admin}}} {"admin" {:username "admin", :password "$2a$10$byP7iTHiHGfrQSf0A/j9ruzFwsEfImweCSaZU45/Zudc2wbauhY/i", :roles #{:slckfu.handler/admin}}})

sb10:01:21

what I need to get: {"admin" {:username "admin" :password (creds/hash-bcrypt "pass") :roles #{โ›‘admin}} "dave" {:username "dave" :password (creds/hash-bcrypt "pass") :roles #{โ›‘user}}}

sb10:01:40

what means () around the result, that is a ... or?

sb10:01:11

As I see.. that is clojure.lang.LazySeq

sb10:01:42

I would like to find similar solution like this (into #{} [1 2 3 4]) ==> #{1 2 3 4}

sb10:01:28

lazy list to map

rauh10:01:44

@sb please always try to format the code. Makes is easier to read

sb10:01:59

@rauh I have the result in lazy seq, that is my problem.

rauh10:01:47

@sb why not (wcar* (apply car/mget test)) and then transform the datastructure from there

rauh10:01:53

But to answer your question: Just do a (into {} (for [...] [key val])

sb10:01:11

thanks!

sb10:01:15

Yes, that is really cool: (wcar* (apply car/mget test)) but unfortunately friend use the datastructure what I shared with you. You query result: [{:username "admin", :password "pass", :roles #{:slckfu.handler/admin}} {:username "admin2", :password "pass", :roles #{:slckfu.handler/admin}} {:username "admin", :password "$2a$10$byP7iTHiHGfrQSf0A/j9ruzFwsEfImweCSaZU45/Zudc2wbauhY/i", :roles #{:slckfu.handler/admin}}]

sb10:01:45

I need to drop plus โ€œuserโ€ field before this.. if I understand good the docs

rauh10:01:21

You mean :username keys?

rauh10:01:35

(mapv #(dissoc % :username) res0

sb10:01:50

Ok, I test it. One moment.

sb10:01:56

Thanks!!

sb10:01:21

Works!! :+1::+1: Thanks for your help!!

sb11:01:04

Hello, Sorry, I have a new question..

sb11:01:40

I try to generate jars with that redis connection

sb11:01:57

but I got error messages.. do you have idea how can I fix it?

sb11:01:50

I think, that is a wrong embed profile setup.. but I didnโ€™t find a good tutorial about.

sb11:01:11

(redis/carmine case)

sb12:01:12

if I add to the dependencies No value supplied for key: [com.taoensso/carmine โ€œ2.15.0โ€] I got this error messages. I tried add value for keys with :env {:redis-host "127.0.0.1" :redis-port 6381}

sb12:01:30

so if have any idea, welcome ๐Ÿ™‚

sb13:01:18

If I comment this lines ` (def testuser (-> (wcar* (car/keys "admin")))) ;(def users (into {} (for [x testuser] {((wcar* (car/get x)) :username) (wcar* (car/get x))})))` of course everything works fine.. at uberjar flow.. so that is something connection problem.

roelof15:01:58

How do I telll that name is a string with spec . I tried this : (s/def ::frontpage-name(string?))

roelof15:01:09

but then I see a arity error

roelof16:01:00

or is Cursive mistaken ?

noisesmith16:01:16

@roelof why is string? being called with no arguments there?

noisesmith16:01:40

I don't know spec, but that looks super weird

noisesmith16:01:07

the lack of space before the ( makes it look like you are trying to write java

roelof16:01:29

I want to test if the keyword :name can only have a string as contents

noisesmith16:01:43

but you are giving two arguments to def

noisesmith16:01:04

one is a namespaced keyword, the other is (string?) which is the function string? called with no args

noisesmith16:01:06

which is an error

roelof16:01:10

yes, the name of the condition and the condition itself

noisesmith16:01:29

what I am saying is that condition is an invalid arity error

noisesmith16:01:36

(string?) is an error

roelof16:01:45

yes, that is why I said earlier

roelof16:01:59

that is also the message that I see also

noisesmith16:01:03

why are you putting parens around it?

noisesmith16:01:08

that's what causes the error

roelof16:01:33

but I do not know how to tell spec that the keyword :name must contain a string

roelof16:01:00

@noisesmith thanks, that seems to solve it

noisesmith16:01:34

@roelof do you understand why I could see it was an error even though I don't know spec? in clojure we don't use parens for grouping (except for a few very rare cases that you can count on one hand) - they are for calling functions

roelof16:01:44

yep, thanks

noisesmith16:01:16

if I were to redo the clojure syntax (or make my own clojure-like) one of the only changes I would make is not using parens on the left side of case clauses (just to reduce that ambiguity - to never have parens as grouping constructs)

fabrao18:01:53

hello all, Iยดm trying to understand specter, so how to select the keys with false values?

(select [ALL <???>] #{{:RES false} {:TAM true} {:ITA true}})

noisesmith19:01:45

fabrao: did you try false? ?

noisesmith19:01:37

oh, you need the nested structure, so it would be more like (comp false? val) wouldn't it...

fabrao19:01:49

I did like this

(->>  #{{:RES false} {:TAM true} {:ITA true}}
       (filter #(= true (second (first %))))
       (map #(key (first %))))

fabrao19:01:48

It seems to be more easy in specter, but I donยดt know how to migrate from this to that

noisesmith19:01:27

fabrao: maybe (comp false? val first) - that would get the first (only) entry in the map, check if the value is false in the entry

fabrao19:01:06

(select [ALL (comp false? val first)] #{{:RES false} {:TAM true} {:ITA true}})
-> [{:RES false}]

notanon21:01:57

@roelof i think you mean (s/def โ›‘frontpage-name string?)

notanon21:01:20

you dont want to invoke string?, you want to pass the function string? as the second argument to s/def