This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-01
Channels
- # aatree (1)
- # admin-announcements (11)
- # beginners (77)
- # boot (73)
- # braid-chat (29)
- # cbus (3)
- # clara (3)
- # cljs-dev (16)
- # cljsjs (2)
- # cljsrn (68)
- # clojure (149)
- # clojure-austin (1)
- # clojure-czech (2)
- # clojure-miami (8)
- # clojure-poland (28)
- # clojure-russia (165)
- # clojure-ukraine (1)
- # clojurebridge (3)
- # clojurescript (64)
- # community-development (1)
- # core-async (27)
- # core-matrix (2)
- # cursive (38)
- # data-science (2)
- # datavis (4)
- # datomic (3)
- # dirac (78)
- # emacs (10)
- # events (1)
- # funcool (6)
- # hoplon (25)
- # immutant (2)
- # jobs (3)
- # ldnclj (34)
- # luminus (4)
- # mount (23)
- # off-topic (26)
- # om (121)
- # onyx (320)
- # other-lisps (1)
- # proton (13)
- # re-frame (33)
- # yada (3)
Given the recent clojure.string
additions, is there anything planned for integers, I find it very interesting that there isn’t a native clojure function for converting strings to ints. A broader question would be, is there a library that deals with coercion from one type to the other? assuming that it doesn’t exist in core
given going from a string to an int looks like this http://stackoverflow.com/a/12503724
FYI, the reason I'm not using a (:gen-class ...)
in the ns declaration is that I don't want users to have to modify their tests to use Gradle. So I'm scanning for test namespaces and trying to call (gen-class ...)
for each, creating a class matching the namespace name.
what about making your own class (via reify or proxy) for each test ns file found, that knows how to load up clojure.lang.rt, load that ns, and run its tests?
To get the right behavior from Gradle, I would need a named class (matching the namespace). My understanding is that reify/proxy don't allow named classes.
I can make due for now with a single class (which avoids the macro evaluation issues), it just causes some incorrect logging from Gradle.
I have a Component that needs to be passed a handler, but the handler must interact with the record's fields
handler needs to interact with status and msg-count, and also call the close
from the Lifecycle
protocol
Somebody wrote
I’ve had type errors in Clojure that multiple professional Clojure devs (in-
cluding myself) couldn’t resolve in less than 2 hours because of the source-to-
sink distance caused by dynamic typing. We had copious tests. We added
println’s everywhere. We tested individual functions from the REPL. It
still took ages. It was only 250 lines of Clojure. I’ve had similar happen in
Python and Common Lisp as well. I did finally fix it and found it was due
to vectors in Clojure implementing IFn. The crazy values that propagated
from the IFn usage of the vector allowed malformed data to propagate down-
ward far away from the origin of the problem. The same issue in Haskell
would be trivially resolved in a minute or less because the type-checker will
identify precisely where you were inconsistent.
I have a hunch that clojure's error reporting was so bad that diagnosis was difficult.
it's certainly possible that a poor error message made the problem described more difficult to solve. the error messages are definitely better. it's also possible a debugger would have helped, which cider and cursive now provide. but there's really not enough information in the comment to tell. fwiw he mentions seeing the same issue in Python, which is usually regarded to have good error messages
my opinion: I just got an error message. java.lang.IllegalArgumentException: The end instant must be greater or equal to the start at com.google.cloud.dataflow.sdk.Pipeline.run(Pipeline.java:180) at link_dataflow.thingy$_main.invokeStatic(thingy.clj:139). this tells me exactly where in my code that happened. I look at it, no it's not a problem that would have been caught by a type checker, it's just that my domain is more complicated than I thought, and somehow comments can happen on topics prior to the topics themselves being created.
hey @jethroksy: a record can be treated like a map- fields can be retrieved with keywords- (:status wsclient-instance) and changes introduced with assoc, which returns the changed record; similarly any protocol fns can be called directly (close wsclient-instance). remember to use the returned instance.
@jonahbenton I want to call handler in start
though
Basically the the handler is a multimethod that consumes everything in a channel and dispatches based on a value
@jethroksy so the record is instance that passes through the channel?
or the record is an owner of the consumption process?
I'm specifically using aleph, so I have a field conn
that stores the duplex stream returned
so status is some state determined by the consuming process, and msg-count is the number of messages consumed off the channel, etc
do other parts of the program need to have visibility to msg-count and status while the consumption process is occurring?
Hey @jethroksy! This is completely unrelated to your question but apparently you are creating a websocket client in clojure. If the project is open-sourced would you mind sharing the link? I tried to implement something similar and a new approach might help me in understanding where I went wrong. Thanks!
Hello @udit ! I'm not actually creating the client, I'm just using an implementation of it (aleph, which uses Netty underneath). I'm trying to make it a component since it makes sense that it has a life cycle. I'd share the snipper now but I'm on my phone :/
hey @jethroksy it sounds to me like it may make sense to decouple the consumption process from the lifecycle of the record. so the consumption process should be started by start, but start has to return an updated record instance to the system, and presumably the consumption process should not block the return of start.
stop should be able to stop the consumption process, but that's separate from the consumption process being completed
gotcha. did you write consume! or does it come from aleph?
gotcha
i don't know the semantics of manifold and aleph off-hand, but in core.async terms, this sounds to me like start spin ups 2 go-loops. the first consumes from the channel, maintains its own internal state around the process of consumption- count of messages, etc- and it is handled a stop-chan and a complete-chan, both of which are part of the record's state. the record loses the "in-flight" state fields but has an "end-state" atom. the second go-loop listens on complete-chan and updates the end-state atom when consumption is done. calling stop on the component puts a signal on stop-chan so the consumption process stops.
what's not clear not knowing aleph and manifold is how those async processes communicate with other parts of a system
It would be great if I could ping you about an hour later, I need to eat my dinner and I'll have code to show you
certainly, i have to run out for a bit too, happy to continue later
hey @mrb welcome
is it a bad idea to load stuff from the user
namespace in a Clojure test? I’m toying with a Duct app and am wondering if it makes sense to re-use user.new-system
from a kerodon test.
hey @stig better to have user consume stuff from other namespaces- including test namespaces, for working with tests at the repl
I’m having a Attempting to call unbound fn: ***
on clj 1.8 without using declare, don’t really know how to troubleshoot this, any ideas?
Thanks @jonahbenton. Assume I’ve done some repl testing; how do I now codify this so that it runs when running lein test
?
@jonahbenton: a good point though. Thinking about it it would be difficult to run from the repl later, if I use the user namespace in my tests.
sure, just add the work you wish to retain to your test namespaces
and yes, it's a good practice to have a test config, and if using component to have a test system.
Under what circumstances is *ns*
bound to clojure.core
even though I used it in a function in my own namespace?
More details: The function is called from pedestal and the "route" function that returns the deref'ed route var. CLJ 1.8
hey @rauh can you say more about what you are seeing?
@jonahbenton: Very much the same setup as this: https://github.com/ohpauleez/pedestal-micro/blob/master/src/leiningen/new/pedestal_micro/service.clj
Request comes in, route function gets evaluated. In it I do a (println *ns*)
and it prints me clojure.core
instead of my ns.
Reason is that I get an exception (and an empty response) if I reload the namespace itself while pedestal is doing a request (my guess). So i wanted to (remove (fn-with-*ns*) (modified-namespaces))
I guess it's only bound to the current namespace while the namespace is loaded. So I just capture it in a simple def
.
hmm. i haven't used that particular template but it should be reloading the namespaces before traversing the route table to find your handler. what exception are you getting?
@meow: True. I've been busy with lots of other stuff but finally doing more clojure again. Thanks, all is well.
@jonahbenton: Thinking a little more about it: It might be that I'm getting that exception because mount (similar to component) will restart pedestal when reloading that namespace.
@rauh ah, yeah, that would be a problem
as a self-taught programmer coming from a deep JS background…. clojure is pretty awesome. just scratching the surface
@solomonhawk: good to hear
found http://braveclojure.com to be amazing
also idk why i didnt pick up emacs before
Does clojure have a packaged function for text dedent? i.e. this https://gist.github.com/jturner314/3807830 (which is the behavior of something like this https://docs.python.org/3.5/library/textwrap.html#textwrap.dedent)
hey @rduplain am not aware of one in either clj or java, though at first glance that gist doesn't look bad. could just copy paste the code into a namespace in your project and use it.
That's what I'm considering. I'd prefer something packaged instead of copy/paste. If it doesn't exist, I will consider forking the gist into a package.
@solomonhawk: emacs is arcane and has bad package support.
👍 how does it stack up right now?
I’m still very new so it’s not easy for me to make that kind of assessment
I tried to get a few packages installed and the system was pretty bad. All of that pain just so parens would line up nicely
basically I think of Atom as modern and would like to see it be the first place people go to program Clojure
from what I saw at the Conj, a lot of people use Emacs but you need to find someone pretty advanced to be able to help you debug your issues. IMO it just wasn’t worth it as emacs provides no “big enough” benefit for the trouble
@tesseract: Well, other than it being built for lisps.
i just started using Emacs less than a year ago, and haven’t had any issues with it. Found it to be a pretty smooth ramp up process.
the resources at http://braveclojure.com were invaluable for me
basically sets you up with a decent emacs config w/ a bunch of clojure geared stuff
been on ST for awhile now
ready for keyboard-only editing experience..
And there is spacemacs for those who want bells and whistles with community supported config
My clojure-Emacs setup works great when it works, but it breaks often after package upgrades. I've been using LightTable more and more lately.
@nkraft: How does the current light table work for Clojure? I haven't tried it for quite a while
Hmm. I feel like I’m having a bit of difficulty redefining a logger in testing. I want to redefine taoensso.timbre/error
in some tests so that I can assert some logging output exists; but it looks like error
(https://github.com/ptaoussanis/timbre/blob/master/src/taoensso/timbre.cljx#L515) is a macro. Any tips about what I might be missing?
Or would a better approach be to redefine taoensso.timbre/log!
the function; this is used by error
?
hey @derwolfe how about just passing timbre a custom appender in test?
jonahbenton: I hadn’t thought about that! I’ll read up and see how to do so. Thanks!
jonahbenton: That was exactly what I needed. Works perfectly -
(timbre/merge-config! {:appenders
{:atom-appender
{:async false
:enabled? true
:min-level nil
:output-fn :inherit
:fn (fn [data]
(let [{:keys [output-fn]} data
formatted-output-str (output-fn data)]
(reset! log formatted-output-str)))}}})
nice! timbre is a very open system
sure thing
LightTable has really come along in recent years. I like being able to run sections of code to see the output, though I miss a true repl.
@tesseract: Have you seen Proton? It is atom plus spacemacs plus parinfer plus REPL - #C0GCNE3B3
@xc4meron: Plenty. Just ask and you should get an answer or a suggestion for a better channel to ask on.
basically, I'm doing clojure as a module and ive gotta do this question and i just need help starting sigh
@meow Proton definitely has potential, but its missing too many of the basic features that spacemacs provides for me to consider it a replacement at this time.
When evaluating the result of a for
loop. Is each element realised sequentially?. I.e. Will it evaluate the element at 0 first, then the element at 1. Or does it evaluate them all asynchonously?
I think there is a parallel for in one of the utility libs out there though
yeah, claypoole has a pfor
@bronsa, @alexmiller. Thank you
Suppose I do something like this:
(do
(doall (map println (repeat "foo")))
nil)
Will it hold onto the head of the infinite sequence of nil
s (and eventually run out of memory), or will that be optimized away because the value is not being used?
(In reality the code is a little more interesting, consuming a stream of data received via HTTP with server-sent events (SSE).)How about something like this?
(do
(reduce (fn [_ a] (println a))
(repeat "foo"))
nil)
Tried running both in REPL while watching the memory usage, the former code causes the memory usage to rise but the latter doesn't
@ijbriscoe: You are looking for doseq
yup, that would do it too. I ended up with map + doall because it looked better with ->>
. I had hoped the return value would not be collected. From @seriousbug's test, it looks like I was wrong. Thanks!
I wonder why slack picked ijbriscoe when I selected @ljosa from the list? Anyway, doseq is intended for use when your body is for side effects (such as printing in your case) and as such does not hold the head. It's idiomatic for this type of case