Fork me on GitHub

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


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


how can I achieve this?


(defrecord WSClient [msg-count status handler conn]
;; ...


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.


Has the source-to-sink distance become shorter now?


the source-to-sink distance is a function of your program's design, so not really


At 250 lines, the distance shouldn't be long.


I have a hunch that clojure's error reporting was so bad that diagnosis was difficult.


there's not nearly enough information in that comment to usefully respond


clojure's error reporting used to be bad.


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


It's probably poor design...


Basically the the handler is a multimethod that consumes everything in a channel and dispatches based on a value


So in start I need to do something like (consume! #(handler %) chan)


And this would then modify the fields of the instance


Eg. (reset! status false) when disconnected


@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 in start I have something like (s/consume! #(handler %) conn)


This handler is stored in another field of the record


I need this handler to be aware of status, msg-count etc


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 no problem. Share it whenever you may simple_smile


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


That's how it works currently


(s/consume!) is the non-blocking process started by start


Stop closes the stream so the consumption process is stopped as well


gotcha. did you write consume! or does it come from aleph?


It comes from manifold



Perhaps the multimethod should take more arguments??


Take the component as an argument as well


I can't think of a way to use closures to fix this


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.


I guess that makes sense, my code would need some restructuring


what's not clear not knowing aleph and manifold is how those async processes communicate with other parts of a system


I could give you a rough explanation


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


Thanks so much for your help btw


certainly, i have to run out for a bit too, happy to continue later


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


This suggests duplicating the test system instead...


(or, the bits I need from it.)


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?


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?


@rauh: Hey there, stranger. It's been a while. Hope you are well simple_smile


@meow: True. I've been busy with lots of other stuff but finally doing more clojure again. Thanks, all is well. simple_smile


@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


also idk why i didnt pick up emacs before


Does clojure have a packaged function for text dedent? i.e. this (which is the behavior of something like this


I'm looking for something to drop into my project.


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.


I am hoping that atom will turn into a world class clojure environment


👍 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


I think atom has nrepl support too


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.


But experiences differ


there’s an obvious learning curve, but the pros outweigh the cons


what works for me won’t work for someone else, the more choices we have, the better


the resources at were invaluable for me


I jumped from sublime text/Atom to Emacs and never looked back


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


One thing I do miss is ST’s CMD+P


grep -r just doesn’t cut it for me now 😕


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 ( 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?


I was incorrect about log, it is a macro as well.


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!


but I did not mean to start this conversation in here, we can take it #C03RZGPG3


jonahbenton: That was exactly what I needed. Works perfectly -

(timbre/merge-config! {:appenders
                                {: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)))}}})


then I can just assert against the log atom


nice! timbre is a very open system


yes. This also feels much nicer than mocking this out. Thanks for your help simple_smile


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


Is there anyone here that can help me with my clojure work?


@xc4meron: Plenty. Just ask and you should get an answer or a suggestion for a better channel to ask on. simple_smile


basically, I'm doing clojure as a module and ive gotta do this question and i just need help starting sigh


@xc4meron: The #C053AK3F9 channel would be good for that.


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


I've only played with it a little bit as I'm quite happy with Cursive.


Spacemacs 4 LYFE


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?


the former

Alex Miller (Clojure team)20:02:52

I think there is a parallel for in one of the utility libs out there though

Alex Miller (Clojure team)20:02:15

yeah, claypoole has a pfor


how can I see the ... x more frames in clojure stack traces?


Suppose I do something like this:

  (doall (map println (repeat "foo")))
Will it hold onto the head of the infinite sequence of nils (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?

  (reduce (fn [_ a] (println a))
          (repeat "foo"))


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!


doall holds on to the head. doseq doesn't


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