Fork me on GitHub
#beginners
<
2017-11-04
>
boldaslove15609:11:01

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

boldaslove15609:11:33

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

tbaldridge13:11:22

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

tbaldridge13:11:46

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

tbaldridge13:11:06

Closed channels always give nils to takes

athomasoriginal17:11:19

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])

noisesmith18:11:30

@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

athomasoriginal18:11:27

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

noisesmith18:11:46

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

athomasoriginal18:11:22

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

alice19:11:01

Anyone use monger?

alice19:11:13

Trying to serve gridfs files using Compojure

alice19:11:23

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

alice19:11:30

but that's a pretty useless solution tbh

alice19:11:06

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

noisesmith19:11:09

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

noisesmith19:11:36

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

noisesmith19:11:51

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

alice19:11:13

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

alice19:11:20

it served the file but differently

alice19:11:35

wanted me to download instead of being loaded in the browser

noisesmith19:11:01

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

noisesmith19:11:39

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

alice19:11:48

I'll give it a shot!

alice19:11:53

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

alice19:11:01

I was using ring/response to return it before

alice19:11:23

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

alice19:11:26

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?

dpsutton22:11:06

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

dpsutton22:11:38

> 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.

dpsutton22:11:07

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

dpsutton22:11:54

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?

dpsutton22:11:34

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

dpsutton22:11:57

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

Lucas Barbosa22:11:05

definitely checking that

dpsutton22:11:18

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

dpsutton22:11:45

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

dpsutton22:11:25

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

dpsutton22:11:51

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 šŸ˜†

dpsutton22:11:54

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

dpsutton22:11:15

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