Fork me on GitHub
#beginners
<
2016-04-29
>
adamkowalski03:04:13

is there any library you guys can recommend for doing matrix algebra in cljs + clj? hopefully something that can compute determinants, eigenvalues/vectors, and row reduction

seancorfield04:04:57

My first reaction is core.matrix but I'm not familiar with it so I don't really know what it does 😐

adamkowalski04:04:21

thanks i’ll check it out

colorvisa06:04:55

Hi, does anyone have experience with organizing assets like css, images, and fonts in clojurescript? In javascript, it will have module bundler like webpack taking care of that. Just wonder we have sth similar or what is the way clojurians would do?

colorvisa06:04:55

for example, I want to bundle font-awesome and bootstrap

adamkowalski06:04:03

i’m not sure if you can actually load css the way webpack does using a module system. most people tend to have a resources/public directory and inside of there you might have a css folder and a js folder etc

adamkowalski06:04:33

then you can use something like figwheel which will watch your cljs/html/css and auto reload everything when anything changes without losing application state

colorvisa06:04:47

that’s what I see in many examples

colorvisa06:04:29

thanks @adamkowalski

adamkowalski06:04:29

i would google around however, I know it is possible to break up your app into separate modules which can then be loaded as needed, because I’m guessing that why you were asking

adamkowalski06:04:42

if it is an optimization thing, then what I suggested above won’t really help you

colorvisa06:04:10

uhm, I also want to break my app into separate chunk that for css, and js

colorvisa06:04:31

actually, I can achieve that by using sth like webpack to do the hard work for bundling assets

colorvisa06:04:47

and use clojurescript load that bundle file to get the assets

adamkowalski06:04:15

read this http://swannodette.github.io/2015/02/23/hello-google-closure-modules/ also when it comes to css you can check out https://github.com/noprompt/garden with garden you can generate css using clojure data structures, and then load them as needed, so you can separate it up into only the minimal css needed for page load. then as people navigate to other pages you can inject the needed css.

colorvisa06:04:47

I checked out that but it doesn’t mention anything about loading css files

colorvisa06:04:01

I like to use garden but sometimes I just want to load the predefined css lib like bootstrap

colorvisa06:04:35

maybe putting in resource folder will make sense in this case

adamkowalski06:04:39

your not a fan of using a cdn? then you could just toss a link into your html

adamkowalski06:04:07

but if you are using bootstrap that is something your whole app will need anyway right? so is the cost of just loading it upfront not worth it for you

adamkowalski06:04:42

so i think it will be fine to just download it and put it into your resources/public

adamkowalski06:04:55

if performance becomes an issue then try something more complicated

colorvisa06:04:21

uhm, thanks for your help 👍

lucj0612:04:19

Hi all, I’m still at the beginning of my Clojure learning path. What is the recommend way to handle exception with clj-http ? From what I see in the doc, a simple try/catch is fine but as I collect the data directly within the let I’m not sure on how to do this ? Any idea ? http://pastebin.com/9cFZJQNA

bruceadams12:04:36

@lucj06: Using slingshot’s try+ is very nice with clj-http, but it’s still a try/catch setup, which sounds heavier than you were hoping for. Just for reference, I hope you’ve read the clj-http doc about this https://github.com/dakrone/clj-http#exceptions

bruceadams12:04:19

There may be a way to ask clj-http to not throw exceptions on error status codes (but you’ll still get exceptions for things like timeouts, those come from deeper down the call chain).

lucj0612:04:57

@bruceadams: yes, I saw this doc but was not sure how to handle this. Is is a good practice to use a try/catch within a let ?

bruceadams12:04:55

I do it: try/catch within the bindings part of a let. I’m not sure if it’s good practice or not. ¯\(ツ)

plexus12:04:34

doing it inside the let bindings would mean you still want the code inside the let to run even if case of an exception

plexus12:04:02

generally you're probably better off doing it around the whole let

lucj0612:04:21

in fact I just want to catch the error if the data cannot be retrieved and return an error message

bruceadams12:04:24

And yet, keeping a try narrow avoids catching exceptions from actions other than the intended one.

lucj0612:04:08

in fact, I just need to catch the www/get error in case API is not accessible

lucj0612:04:03

in the doc exemple the result of the www/get is not directly assigned to something

lucj0612:04:22

so the try/catch is done directly around it.

lmergen13:04:37

i just discovered the advantages of transducers, holy shit this provides so much more flexibility!

lmergen13:04:48

it's like a map, or reduce, but then having the entire context at your disposal, instead of just a single item

lmergen14:04:31

am i correct that transducers are the preferred way to go if the transformation i'm trying to do are more complex than a typical map operation allows to do ? for example, transform a big nested structure into a "flat", denormalized object ?

plexus14:04:23

Probably, yes. A big benefit is that they will transom your data in a single pass, instead of generating intermediate representations

bruceadams14:04:31

@lucj06: note that data will be bound with whatever value log/error returns (maybe nil?)

lucj0614:04:40

@bruceadams: hum I agree… this is bad. Any advice on how to do this ?

lucj0614:04:53

in a more Clojure way ? simple_smile

lucj0614:04:13

I should probably return nil with each catch

lucj0615:04:45

@bruceadams: I do not get, from the doc, how you can affect the result of the request (let’s say it’s an api that return json) to a var.

bruceadams15:04:28

@lucj06: I’m not sure I understand what you are asking. Each catch can contain multiple forms, can return nil from one like this:

(catch [:status 403] {:keys [request-time headers body]}
    (log/warn "403" request-time headers)
    nil)

lucj0615:04:04

@bruceadams: in fact, I’m not sure what is the correct way to mix let and catch in my case. Should I embed try/catch in the let or the other way round ?

bruceadams15:04:14

So, I can see that you want to log a message for failures (which makes sense). What happens next? Where do you want your program to go from here?

bruceadams15:04:39

(In my one serious use of clj-http, my try+/catch was typically much higher up the call chain, not very near the call to clj-http. I assumed, up at that higher level, that anything with a numeric status came from clj-http.)

lucj0615:04:12

thanks, things are much clearer now. In my case, I need to send a json or nil.

lucj0615:04:00

Thanks to your help, I've understood several things of Slingshot.

puhrez21:04:15

I’m curious whether there are any docs that would explain the craziness that is a modern flexible clojurescript development environment

puhrez21:04:32

because entering it now new is rather daunting and confusing given all the tools

puhrez21:04:10

like one enters the clojure world and picks up emacs/cider because not to high learning curve and (eventually fulfilled) promises of ease of development

puhrez21:04:31

then one enters the clojurescript world desiring the same sorta dev env

puhrez21:04:44

only to encounter… well not so fast there etc .etc.

puhrez21:04:54

then one finds figwheel, ah! beautiful!

puhrez21:04:59

wait what about cider...

puhrez21:04:03

components?

puhrez21:04:09

figwheel-sidecar?

puhrez21:04:12

piggieback?

puhrez21:04:15

</(rant|cry for help) >

bwstearns22:04:27

@puhrez: the clojure/cljs community has a lot of really awesome tools. So far I’ve just been focusing on using the ones I need at that moment and keeping aware of the general shape of tools that I don’t need so that I don’t miss a good reason to learn them. Setting up leiningen with custom profiles, and hooking it up to cider and getting emacs set up (for those of us who are not emacs-natives), etc. is a lot, and also, by the end of that list: you haven’t written any code!

bwstearns22:04:34

So I’d say prioritize the stuff closest to writing code (figwheel, components) before the environment stuff like emacs/cider unless you have a particularly strong urge to learn those things (I’m assuming you have a meaningfully finite amount of time to spend on clojure stuff, otherwise just learn everything! lol).

puhrez22:04:51

@bwstearns: the thing is I’ve written clojure code, to production even! but now that I’m like let me take the full stack approach I want to maintain the same dev experience I’ve had with emacs/clojure/cider the whole figwheel stuff seems so familiar but oddly difficult to integrate

bwstearns22:04:32

@puhrez: oh cool. I've just been using clojure for personal stuff so far so you're way ahead of me there. I think the thing is that there are just a lot of tools that all play together and it's a young enough ecosystem that there isn't a one true way yet. It might also be a touch of the lisp curse in that people can hack stuff together easily enough often enough that a lot remains in the state of solving "my 80%" of a problem instead of getting fully generalized.

puhrez22:04:08

yea that’s definitely a factor

puhrez22:04:18

i guess it just means that it’s ripe for contribution!

bwstearns22:04:29

:D I'm commuting or I would cite specifics but I've experienced a lot of clojuretv's videos on YouTube being helpful for tool setup because watching someone set it up can be easier than reading a howto since you can see the rest of files that may make assumptions that you weren't aware of.

dorab22:04:53

@puhrez: Have you looked at https://cider.readthedocs.io/en/latest/up_and_running/ especially the section "Using the Figwheel REPL (Leiningen-only)"

puhrez22:04:47

this is beautiful