Fork me on GitHub
#beginners
<
2017-03-21
>
abhiroop04:03:54

@seancorfield How do you understand which functions should be part of core and which ones not?

seancorfield05:03:31

@abhiroop Well, my opinion is just my opinion, but core should be basic building blocks, and anything you can easily build on top of that is not necessarily part of core (as a loose guideline).

seancorfield05:03:31

@abhiroop Well, my opinion is just my opinion, but core should be basic building blocks, and anything you can easily build on top of that is not necessarily part of core (as a loose guideline).

abhiroop14:03:03

@seancorfield For example the clojure ‘core’ has both map and pmap defined. But in case of reduce we get only the single threaded version in core whereas we have a library outside core (Reducers) to parallelize this. Why can’t parallel folds be part of the core? Is there some thumb rule to decide this? As such shouldn’t all parallel/concurrent functionalities exist as separate libraries or atleast namespaces?

noisesmith17:03:28

pmap shouldn’t be in core - it’s a proof of concept but makes too many assumptions that probably don’t hold for your code to be generally useful. Code that uses pmap is probably doing something wrong in my experience.

seancorfield17:03:09

@abhiroop The reducers library — which is a core namespace — has parallel folds: https://clojure.org/reference/reducers

grounded_sage05:03:23

What would be cool is a public utility functions library. So people can easily copy functions put together by others. Not a library you pull down but a reference online.

foamdino08:03:19

@grounded_sage like clojure-cookbook (which I discovered yesterday)

grounded_sage08:03:04

@foamdino I was thinking that. But I think something even more like http://clojuredocs.org where the function is described anyone can put in examples etc. Then maybe people could vote, comment on them etc

camdenclark08:03:29

one resource when I was learning to use pandas (the python dataframe library) was a paste that had a bunch of interesting snippets the creator had used frequently. Something like that might be useful but for anything else a google search for a stack overflow post is more useful.

sb16:03:40

Hello, how can I assoc a new user to a variable?

sb16:03:36

That is works fine in repl, but just in the function changed the variable (binding). How can I modify the map (like global variable)?

sb16:03:28

because everytime I get back the original var (else case), could you help me?

sb16:03:56

(update-in users [username] assoc :username username :password password :role #{::user})

sb16:03:27

that is work too.. but not update the original variable which contains the user data (it loaded once from the database, when started the website)

donaldball16:03:00

You may be looking for atom and swap!

sb16:03:17

Yes, but the Friend not store in atom the user data..

sb16:03:50

Ohh.. maybe I can define a variable which use an atom?

donaldball16:03:56

alter-var-root! lets you change the value of a var, but many would advise only going down that path with very good reason

donaldball16:03:20

yes, that would be much more common, putting an atom value in a var

sb16:03:37

(def users @userdb) is correct?

donaldball16:03:01

That would set the value of the user var to the current value of the thing referenced by userdb

sb16:03:16

Friend use the users var

sb16:03:24

I would like to update this

manutter5118:03:15

@sb the documentation for Friend is using users as a substitute for a real database, so the example will be simple.

sb18:03:34

yes, but I can’t update

sb18:03:38

I don’t know why

sb18:03:30

I tried with that too

(let [user {"ewq" {:username "ewq" 
                            :password (creds/hash-bcrypt "pass") 
                            :roles #{::user}}}]           
            (friend/merge-authentication (ring.util.response/redirect "/testdb2") user))

manutter5118:03:30

If you are just trying to learn Friend, it’s ok to use an atom instead of an immutable variable

sb18:03:48

Yes, I would like to use Friend

manutter5118:03:11

I am looking at the Friend example here: https://github.com/cemerick/friend

manutter5118:03:40

If you would like to be able to make changes to that “toy” user database, you can define it like this:

manutter5118:03:01

Then you can update it with (swap users assoc username {:username “joe” :password “whatever” :roles #{::user}})

manutter5118:03:42

or (swap users assoc ”joe" {:username "joe" :password "whatever" :roles #{::user}})

sb18:03:02

Thank you very much! :+1: :+1: :+1:

manutter5118:03:10

oops, make that swap! not swap, I always do that derp

sb18:03:26

:+1::+1::+1::+1::+1: I really thank you for your answer, really helpful! I got the answer. thanks!!

manutter5118:03:38

by the way @sb if you haven’t looked at Buddy you might want to take a look, as a possible alternative to Friend https://github.com/funcool/buddy

sb18:03:23

Yes, I heard from many Clojure devs, they use buddy. I will check it. Thanks! 🙄:+1: