Fork me on GitHub
#beginners
<
2018-02-18
>
Vincent Cantin06:02:11

What is the difference between (defn ^:private my-fn ...) and (defn- my-fn ...) ? Both of them can be found in clojure.core. For example: https://github.com/clojure/clojure/blob/clojure-1.9.0/src/clj/clojure/core.clj#L7532

reborg08:02:23

@vincent.cantin no difference. Possibly some functions were moved around after the definition of the defn- macro over time https://github.com/clojure/clojure/blob/clojure-1.9.0/src/clj/clojure/core.clj#L4865

rauh08:02:24

@vincent.cantin It doubles up on the reduced since the reduce call a few lines down in cat needs to know if it was stopped by reduced

rauh08:02:57

If so, it needs to return the reduced object (not the value it holds) since the transduction needs to stop.

Strate09:02:09

hi there, im trying to use lein from the command line

Strate09:02:22

but it gets stuck ... can't even do lein new poject_name ..

Strate09:02:11

Could not transfer artifact lein-ancient:lein-ancient:jar:0.6.10 from/to maven-public .. interesting

gklijs09:02:21

lein help does work?

Strate09:02:04

im trying.. i think it tries to connect to a cached repo

Strate09:02:35

ok, so now it works

ackerleytng10:02:12

i'm looking at the A* implementation in the joy of clojure. I'm trying to understand why the algorithm does not step forwards and backwards between, say, [0 0] and [0 1]

Vincent Cantin10:02:39

Does it exist a transducer equivalent of tree-seq ?

Vincent Cantin18:02:35

I made a transducer version of tree-seq which seems a lot faster than the original and the improved POC on github. https://gist.github.com/green-coder/3adf11660b7b0ca83648c5be69de2a3b

Vincent Cantin18:02:02

Transducers really rocks!

sundarj18:02:20

nice one šŸ™‚

ackerleytng10:02:48

Think i got it. When the algorithm is working on [0 1], it will add [0 0] as a new work item when [0 0] is checked again, the algorithm will look up the neighbors of [0 0], trying to find the cheapest path to get to [0 0]. It will compute a newcost, which will inevitably be higher than the existing cost to get to that position, hence the todo list does not grow. this prevents an infinite loop

Dos10:02:02

What says the clojure-community about ORM? Especially Rich...

ghadi14:02:52

Rich is not a fan of ORMs, neither is most of the community

Dos17:02:36

thank you sir, jazakaLLahu hoir

sggdfgf13:02:04

Could this be destructured: `(fn [dims] (let [dimensions (js->clj dims :keywordize-keys true) width (:width dimensions) height (:height dimensions)]` I only want to keep width and height.

eskos13:02:39

(let [{:keys [width height]} (js->clj ... should work.

ghadi14:02:53

Width and height at extracted after conversion not before

Reuben Steenekamp14:02:30

Hello all. I'm struggling to include :npm-deps {:rmwc "1.2.0"} into my build. It claims to not be able to find react, even when I include cljsjs/react in my dependencies.

Compiling ClojureScript...
ā€¢ js/dashboard.js
ā€¢ js/devcards.js
events.js:182
      throw er; // Unhandled 'error' event
      ^
Error: Cannot find module 'react' from '<redacted>/node_modules/rmwc/Button'

gklijs15:02:19

:npm-deps is still a bit buggy I believe, depending on the library. You include react also with :nmp-deps?

Reuben Steenekamp15:02:12

I tried, but then it complains that it cannot find module './ReactInternal'.

Reuben Steenekamp15:02:03

All I want is a Material UI library that I can easily use. react-mdl is deprecated, material-ui pulls in it's own react and react-dom (which isn't too bad but I want to avoid it) and rmwc isn't on cljsjs. Any other suggestions?

sundarj16:02:35

you might want to ask in #clojurescript

donmullen16:02:06

@reuben.steenekamp Iā€™m just starting to look at material-ui ā€” and it looks like material-ui-next https://material-ui-next.com - doesnā€™t pull itā€™s own but uses 16.0. Where did you see material-ui pulls in own react and react-dom?

Reuben Steenekamp16:02:16

I mean't from cljsjs From https://github.com/cljsjs/packages/tree/master/material-ui:

cljsjs/material-ui comes with its own cljsjs/react and cljsjs/react-dom.

justinlee16:02:32

@reuben.steenekamp one thing to note: shadow-cljs has a mechanism to deal with the fact that many libraries import from cljsjs. it basically shims them so you can install from npm

donmullen16:02:48

@reuben.steenekamp Got it - with shadow-cljs this wouldnā€™t be an issue.

justinlee16:02:02

@reuben.steenekamp if you are going to be importing a lot of javascript libraries iā€™d strongly consider using shadow-cljs, which makes this stuff easier because you just install using npm or yarn. but if you want to get it working using the normal clojure compiler, you will need to import using :foreign-libs

justinlee16:02:31

this is how I got react-dnd to work

:foreign-libs [{:file "resources/lib/ReactDnD.js"
                :file-min "lib/ReactDnD.min.js"
                :provides ["react-dnd"]}]

justinlee16:02:39

before i moved to shadow i just copied the UMD build from the /dist directory of the node_module into my source tree and then pointed the compiler to it using a :foreign-libs like the above

Reuben Steenekamp16:02:15

Cool, I hadn't heard about shadow-cljs, will check it out.

Henry18:02:40

Alohaa, another question for Reframe. How do I access a value in the state just once, without subscribing to it? Is this possible or is it totally the wrong approach?

Henry18:02:58

For example I have a list of Users in the State which I want to go through in the frontend, to see if it contains a certain value. I just want to do that once when I press a button for example, without rerendering everything.

Henry18:02:46

similar way in React would be ā€œMapStateToPropsā€ and the i can access them easily

Drew Verlee21:02:42

can anyone think of a more straight forward way to build up hashmap? (def board (zipmap (range 1 9) (repeat {:player-id nil})))

joelsanchez21:02:09

as always, there's a way to do it with for if you prefer (into {} (for [n (range 1 9)] [n {:player-id nil}]))

lilactown22:02:09

I have an app that Iā€™m currently storing some state inside of an agent, and I would like to update the data inside of that agent once a day

lilactown22:02:28

is there a library or idiom for doing something like that?

ghadi22:02:02

@lilactown you don't need a library -- one idiom is this:

ghadi22:02:41

(import '[java.util.concurrent
            TimeUnit
            Executors
            ScheduledExecutorService])

(defonce threadpool (delay (Executors/newScheduledThreadPool 1)))

(let [a (atom {})]
    (.scheduleAtFixedRate ^ScheduledExecutorService @threadpool
                          #(update-my-atom a)
                          0 ;; delay
                          refresh-interval TimeUnit/MINUTES)
 ;; return the atom
 a)

ghadi22:02:59

make the atom, pass it to a background function that is periodically called

ghadi22:02:49

there are many other ways to do it. can use a future that loops

noisesmith22:02:03

I think the important distinction there is "once per day per process" or "once per day in the world" - scheduled thread pool works great for the former, for the latter you need some inter-process communication

lilactown22:02:13

yeah, per process

noisesmith22:02:06

I prefer the scheduled thread pool because it gives you transparency and introspection that a future doesn't

lilactown22:02:04

Iā€™m not familiar at all with the java threading/scheduling APIs - so itā€™s going to take me a bit to unpack this šŸ˜…

noisesmith22:02:35

@lilactown the handy thing is that normal functions are callable - so you can just pass a function of 0 args to be executed

ghadi23:02:52

I'd read the docs on the ExecutorService and related classes. Very well designed

zlrth23:02:31

question coming from my naivete w/r/t web development: I'd like to serve multiple websites from one linux box with one IP address. Ideally, there'd be some Clojure way to do that. Let me know if there is! I think though I have to set up nginx or apache. What gives me pause is, to configure either of them, I have to specify where .html files are. I'm using clj-http and compojure. I'm not sure how much I have to change my clojure apps to accommodate what I want to do. Ideally, I could just point nginx to two different java processes for two different URLs. I doubt that's how it works, though!

Vincent Cantin18:02:35

I made a transducer version of tree-seq which seems a lot faster than the original and the improved POC on github. https://gist.github.com/green-coder/3adf11660b7b0ca83648c5be69de2a3b