Fork me on GitHub

I need a "infinite loop" that every "5" seconds fetch a API and insert data in a channel In some situations, I wanna be allowed to stop this service and start it again. Should I use thread, async/go, future-call? There is many options and I cant decide.


Do you want the responses to be in the channel in the same sequence as the requests that made them?


What routing libs are the kids using nowadays?


Are they hanging on to their grandfather’s Compojure?

😀 4

@dominicm i think the framing is wrong: the question isn’t whether they are constants but whether they are globals. there is (some) value to calling attention to that.


@henrik I am still on Compojure

👍 4

@henrik We use Compojure mostly at work, with Bidi on one of our apps. We may use Bidi more in future since it separates routes from handlers better (and allows for bidirectional route naming).

👍 8
↔️ 4

@lee.justin.m Globals as opposed to... local bindings? Do they need separate naming conventions? Surely you can see a local binding on the same screen as the code that uses it? (or else you should probably refactor your function into smaller functions)


Would you argue "global" functions should have a different naming convention to local bindings of functions?


Any symbol that isn't obviously and visibly a local binding (or argument) must be global by definition, right? I'm having a hard time accepting that different naming conventions are needed for that...

👍 4

I think it is helpful and it doesn’t hurt. But I’m just offering my view


commas in english text aren’t strictly necessary, but they improve readability


I find it particularly helpful in communicating that “this is an arbitrary parameter” like 200ms of delay or something like that.


Commas in English text have semantic meaning so, yes, that are necessary.


Commas can't just be randomly added and taken away. They're not about readability.


Compare: "Let's eat, grandma!" vs. "Let's eat grandma!"


Perhaps editor support would help. Different color based on binding type.


hey guys, I want to read from stdin as it is written to by another program, doing (slurp *in*) works, but only if i've received EOF. What I want instead is to know about more data and be able to react to that as it comes in (similar to epoll/select in C). It seems like there may be a way of doing that with channels, but I'm not really familiar enough with them to put it together yet. If anybody has some tips it would be helpful 🙂


@U36FXS8SD you may create a BufferedReader and read from it - e.g. line by line:

(let [rdr ( *in*)]   
  (.readLine rdr))


this will block until it gets more data?


Seems to work. I ended up having to do

(let [rdr ( *in*)]
    (doseq [line (line-seq rdr)] ... ))
but you got me pointed in the right direction, thanks!


line-seq calls .readline with lazy-seq if I remember correctly. Doseq goes all the way around to realize the sequence. You should just call .readLine directly


Maybe with a type hint to avoid reflection and make ir faster.


shouldnt it just return a string?


I think the .read method returns a character and you can read until eof.


And .readline the next string until EOL.


you were saying to call readLine with a type hint, but isn't it always just string?


Indeed but as far as i know . Notation uses reflection either way.That can slow production code. Just

` (set! *warn-on-reflection* true) 
`on the repl and see it for yourself. @U36FXS8SD


Warn-on-reflection inside earmafs


is it possible to inline predicates in a spec? Assume that I am checking maps with three keys :foos :bars and :op where :foos and :bars are always vectors - but the structure of their elements is dependent upon the value of :op. Assuming that :op could be be 1 or 2 - Is there a way of achieving something like

(s/def ::check-op-1 (s/keys :req-un [[::op op-1?] [::foos foo-1-pred?] [::bars bar-1-pred?]]))
(s/def ::check-op-2 (s/keys :req-un [[::op op-2?] [::foos foo-2-pred?] [::bars bar-2-pred?]]))
(s/def ::valid-data (or ::check-op-1 ::check-op-2)))


@henrik I can never remember the bidi syntax, so i still use compojure for simple stuff, and bidi for everything else

👍 4

is there any tool that helps with replacing all the :refer :all in namespace declarations with :as something and then prefixing all the vars accordingly?


I would like to clean up a project that uses that all over the place without having to do it manually since it would take ages


that's quite nice actually but I can do similar things with Emacs and projectile probably


it's more important to have enough knowledge about the project like refactor-nrepl has to really do it in one go maybe


I wonder how hard would it be to write a program that does it, using the Clojure reader. But I’d probably use sed or something similar…


well it's not so easy/possible with sed since it would have to find where something comes from


assuming there are many :refer :all per namespace


if there is only one it could be doable but you would still have to know which symbols to replace


and well probably need to do something ad hoc, I thought maybe Cursive or something else was able to do that


@andrea.crotti clj-refactor for emacs has some tools for that. For instance

👍 8

ah nice. it's failling on this project now but I can try that in other projects as well

Al Baker13:07:30

is the etaoin library for webdriver based testing still in vogue as A Good Thing or has it been surpassed by another library/methodology?


Hi. Is a single spit into a file atomical? I want to make sure that either the old content is left in or all the new data is written.


If there’s a power failure or something, it might not be. The safe way is 1) write new data to a file with a tmp name, 2) rename the old file to file.bak, 3) rename the new file to the correct file name. That way you’re as sure as you can be that your old data is there until the new data is fully written.


Right, or use some 3rd party solution. I was just hoping that maybe it's a built-in feature for the single write.


Hello all! Quick question? I’ve noticed when I used either pmap or Thread/sleep 100 (don’t know if it’s one, the other, or both) causes my Clojure program to require 30 seconds before exiting, as if waiting for a thread to be killed. I seem to recall there was a Clojure call that “kills/cleans-up all threads” so the program can exit quickly/cleanly — can anyone point me in the right direction? Thank you, as always!


Yes! Thanks so much, @the2bears! Iit was one of those things I just put up with (just hit Control-C), but part of me really wanted to figure out how to actually fix it. 🙂

👍 4

I am using bidi make-handler for routing but it seems / is required. "something" something-handler doesn't work when called like - any idea how I can make non / redirect to /. Should I really create a redirection for every route?!


Bidi is data, so automatically adding the routes is easier


what are the best clojure/java authentication libraries


im looking for some set of libraries at least on par with Passport.js


With deps.edn, is there a good way to have several projects in a single repository which share a single set of pinned dependencies? I’d like to have something akin to a versions.edn which just pins versions for dependencies, which deps.edn files can reference.

Alex Miller (Clojure team)21:07:49

default-deps is a nod in this direction and something we want to enable, but not really practically useful yet. Needs a bit more work


unlike boot and lein, deps.edn is Just Data.


that's my semi-sarcastic answer at the end of a long day simple_smile


something like a parent pom, a project that is just there for common deps, could be a thing


nothing baked in (yet), but trivial with a small build step


Hah no worries Ghadi, I’m currently trying to replace a fairly involved set of lein projects with something that’s at least Mostly Data (TM) mainly for classpath caching and simplified impact analysis.


Small Build Step is also (TM)


Looks like the “easiest” thing to do is a custom runner which uses the deps machinery under the hood, and comparable bash script to $ which clojure that can handle the cache check/hit logic.


I think the caching currently includes a timestamp check, too


Since really what I want is effectively middleware - of which deps has none because exposing arbitrary middleware defeats most caching 😕


it may also be easier if you break it in to parts


there are at least 2 parts. 1. specifying commons deps in one place and 2. ensuring all projects are using a specified version of certain deps


#2 seems like the biggest bang for the buck, just some tool to scan deps.edn files and throw an error if the expanded deps map uses a different version of a dep, and then make it part of your test suite


Untested; You could also use a top-level deps.edn only, and aliases to mix in the correct versions, along with the :default-deps key @arrdem


> :default-deps provides a set of default coordinate versions to use if no coordinate is specified. The default deps can be used across a set of shared projects to act as a dependency management system:


It depends on how much varies with the subprojects


Hum, that may be close enough for what I need.


I think you can trigger default-deps by making the rhs in the deps map nil


That’s what it looks like - which is actually exactly what I need.


I'd be curious to see how that works out.


Cool that totally lets me fake this well enough.


Thanks Ghadi!


I promise I’ll write up an experience report once this works out 😉

Alex Miller (Clojure team)21:07:24

We would definitely like to have a clean path to do this. It is In Scope. :)


Hum yeah it doesn’t look like there’s a way to bolt on another source of deps data atm beyond the “$PWD/deps”, CLI args and the config, and I’d like to avoid making my coworkers install user level configs.


arrdem for now I think you'd have to put everything in the top-level deps edn:

{:deps {whatever...}
  :aliases {
  :versions {:default-deps ....}
  :subdir1 {...}
  :subdir2 {...}}}


Sorry for the pseudogarbage. Then you'd launch with clj -A:versions:subdir2


no need for user-level config


Computer, do what I mean not what I say


Yeah that’d definitely work Ghadi, and wiring CI up to run that would be pretty straightforwards.


the version alias would have :default-deps, all other aliases could be free form (mostly extra-deps / extra-paths)


Is quartzite still the best way to do cron-like tasks?


I recently used tea-time for that stuff. If you care about dates and not just time also consier tick


I’ve also used Chime ( for a couple years in production and it works just fine.


On AWS, I use Cloudwatch


I went with factual/timely recently to schedule a task