Fork me on GitHub

is closing a core.async chan generally a bad idea?


it executes body in a go-loop in a non-stop manner


No, closing a chan is a very common operation. @boldaslove156


When you take from a channel you should check for a nil value and terminate the loop


Closed channels always give nils to takes


What does the syntax look like when destructuring a JS event object? For example, is it possible to go from

(let [width  (.-offsetWidth event)
       height (.-offsetHeight event)])
to something like this:
(let [{width .-offsetWidth height .-offsetHeight} event])


@tkjone you could write a macro that does that. let uses clojure.core/destructure to create its binding form and does not expand access macros like that, but it could be done by replacing let with something that uses an expanded destructure, or having a separate macro meant to be used inside a let block


Good to know! I will likely explore making this happen to practice macros, but would this be something valuable in production code?


if it makes a syntax that is useful 😄 - be warned though, destructure is a pretty intense macro helper and emulating it is likely a big task for a beginner


Yeah, so probs not worth the effort at this point in time. Thanks!


Anyone use monger?


Trying to serve gridfs files using Compojure


and right now I just write the file to the disk and read it


but that's a pretty useless solution tbh


any way to read a GridFSDBFile or whatever the object is into just a File object and serve that?


on the JVM File is not an abstraction - it is a specific concrete source of data


so to make code that's more abstract you don't use File, you use things like InputStream or OutputStream or Reader or Writer


but, pretty much anything you can use to get or put data can be made into one of those easily


See, I was serving a pipedinputstream, or outputstream? one of the two


it served the file but differently


wanted me to download instead of being loaded in the browser


OK - that is about how you formatted the response object and headers


if you do {:body my-stream :status 200} that usually does the right thing if that's what you want to directly go to the browser


I'll give it a shot!


@noisesmith took a second to remember how I wrote the pipe-input fn before but it worked!


I was using ring/response to return it before


I read an article that said I had to do it that way to make sure the file didn't come out scrambled and got handled by the browser


but i was lied to lmao

Lucas Barbosa21:11:36

I am reading the SICP book, on chapter 2, and the authors introduce this concept of “Data-Directed Programming and Additivity”. It’s basically a dispatch table that generic functions can lookup in order to dispatch on type. Is this needed in Clojure or the constructs like Multi-methods are enough?


can you tell me which section in chapter 2 you are talking about?


> We would need to identify this new representation with a type, and then add a clause to each of the generic interface procedures to check for the new type and apply the appropriate selector for that representation.


that sounds like everyone's arguments against algebraic types and closed extension people have been talking about


but as the reference shows, Clojure can do that. The definitions in scheme for magnitude and other operations on real and imaginary numbers can certainly be done in the same way they do there

Lucas Barbosa22:11:37

I am unaware of what you said, about arguments agains algebraic types and closed extension. Can you elaborate on that? Pardon for my ignorance

Lucas Barbosa22:11:26

And would I really need to do that in Clojure? I mean, it is possible, but can’t I just use the dispatch constructs that come with the language?


oof, kind of a touchy subject right now. but there's been a bit of a static / dynamic type argument going on. And people in favor of static type systems have pointed to the exhaustive checks available with algebraic types. But the clojure community highlights multimethods as allowing for these switch clauses to be arbitrarily extended


if you check out #other-languages some people have some great arguments and discussions

Lucas Barbosa22:11:05

definitely checking that


no, you certainly don't need to implement the way SICP is doing htere. Clojure has ways to do that


but there is value in following along with SICP in a scheme or staying true to it because when you start implementing protocols or multimethods you'll understand what is going on


the same thing for streams coming up in chapter 3 or 4. Clojure has a lazy stream type but there is value in building it yourself and seeing how it's just a value and a function underneath


ps, that's a great book. and i hope you're reading the online version that has really nice typesettings

Lucas Barbosa22:11:16

Got it! Yeah, I have been trying to stick with their way for learning purposes, and it is working

Lucas Barbosa22:11:48

there are some problems, especially with cons, but I’m having some great times by reading it

Lucas Barbosa22:11:21

I actually bought a printed copy 😆


i own one as well. but the oneline version is easy to have up on screen next to emacs and a inferior lisp repl. it's really fun because that's probably a similar setup to the authors.

Lucas Barbosa22:11:56

I’m also watching the respective lectures after reading the book sections, and it is really funny when they start typing code in that old repl


if you're look for a conference, Sussman, one of the authors, is speaking at clojure sync in new orleans in february