This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-04
Channels
- # beginners (56)
- # boot (11)
- # cider (1)
- # clojure (112)
- # clojure-denmark (4)
- # clojure-russia (7)
- # clojurescript (45)
- # component (1)
- # cursive (19)
- # data-science (10)
- # datacrypt (1)
- # datascript (22)
- # datomic (3)
- # defnpodcast (2)
- # emacs (4)
- # fulcro (26)
- # hoplon (21)
- # jobs-discuss (5)
- # klipse (5)
- # onyx (8)
- # portkey (1)
- # re-frame (8)
- # reagent (17)
- # ring (7)
- # shadow-cljs (14)
- # spacemacs (9)
- # vim (4)
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!
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
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
@noisesmith took a second to remember how I wrote the pipe-input fn before but it worked!
awesome
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
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?
2nd edition
page 179
> 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
I am unaware of what you said, about arguments agains algebraic types and closed extension. Can you elaborate on that? Pardon for my ignorance
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
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
Got it! Yeah, I have been trying to stick with their way for learning purposes, and it is working
there are some problems, especially with cons
, but Iām having some great times by reading it
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.
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