Fork me on GitHub

Does anyone have an opinion on translation/internationalization libraries like Pottery, Tempura or Tongue?


I've used tempura, pretty easy, like it a lot.


I have used Tongue a lot and am quite happy with it


Is there a word (or a predicate) for a thing that is a coll? but not a map? I guess not?


I'm looking for something that would return true for a set.

Alex Miller (Clojure team)15:11:40

does not include sets, but that's the most often thing I use narrower than coll


All right, makes sense, thanks.

Alex Miller (Clojure team)15:11:25

but then you have to ask, what am I doing? is it really right? :)


Yeah, I've been trying to ask myself that. 🙂 I'm trying to write a docstring for a function that accepts a list (but not just a Clojure list) of things.


A map is also a collection of kv pairs. If your function can't accept kv pairs but requires something specific then it would simply be "a collection of the-thing?" or something like that.


Right. An example would be a function that calculates the median of a collection of numbers. A list, a vector, a set, or an array all work, but a map doesn't.


a map doesnt work because it is a collection of map entries, not numbers


Oh, yeah. I was overthinking it. That's a good point, thanks. 🙂


Just to pick on that example (only because I've been working with medians/percentiles recently too), there's a lot of nuance to this: > A list, a vector, a set, or an array all work Like it has to be sorted, and a set of numbers wouldn't truly yield you a median (ie (into #{} [1 1 1 1 1 1 50])). So this example isn't super convincing for the case of it being a core function

Alex Miller (Clojure team)16:11:11

"seqs to nums" is probably closest to what you want (ignoring sorting)


Been seeing this lately OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release. even though I have verify -like flags set nowhere. Is there some less obvious way in which the warn may be triggered?


are you using lein?


yes thanks! yeah I suspected it had to do w/ lein's first jvm


So, I’ve somehow managed 25 years of (un)professional software development and have yet to understand regular expressions really. I’m working my way through O’Reilly’s Introducing Regular Expressions, which recommend the following sed, to extract the first line of some text and wrap it in <h1></h1> tags :

sed -n 's/^/<h1>/;s/$/<\/h1>/p;q' rime.txt
I’ve converted this into the following Clojure that works, but am disappointed that it doesn’t really lean heavily on regex but rather string concatenation.
(str "<h1>" (re-find #".+" rime-intro) "</h1>")
I’ve tried a few ways of writing regexes to capture the first as a group and use replace but not work. How would seasoned Clojure regexers tackle this easy challenge?


the sed command is performing a series of transformations in order, matching the start of a line and putting in a <h1> and inserting a closing </h1> at the end of each line. In java regexes you need to specify the mulitline switch, so I think your sed example is a bit more like this:

(require '[clojure.string :as str])
  (let [txt (str/join "\n" ["title 1" "title 2" "title 3"])]
    (-> txt
        (str/replace #"(?m)^" "<h1>")
        (str/replace #"(?m)$" "</h1>")))


> How would seasoned Clojure regexers tackle this easy challenge? They wouldn’t? RegEx is a tool often best used when other more human-friendly approaches fail for some reason.


Yeah, I’ve heard that opinion too many times for it not to be true!


Yeah ... Having done a whole bunch of perl in my time, regex + html brings me out in hives ... For my money, this problem is better solved by "parsing" the input with something like clojure.string/split , processing with map and joining them together again ...


Haha, consider me well warned! I just want to understand regexes enough to know when to use them and how so. I’m well aware of their maintenance burden as well having inherited a few in my time 😢


99% of what I know about regexs I learned from Java’s docs on Regexes, Grep’s docs, and playing with them in an editor to mess with blobs of semi-structured data. You can go REALLY deep on regexes, but “play” + a few concepts gets you most of the way (in my experience)


well, that re-find is entirely superfluous


the thing with the sed example is it is not purely a regex operation


sed is a stream editor where you can use regexes to drive editor operations like selecting text


The book offers both a sed and perl example and both use program constructs and not purely regexes to tackle this problem. Perhaps how I should do it relies on stuff introduced later in the book, so maybe I’m jumping the gun…


I don't think you've made something entirely equivalent in functionality either, sed is operating line by line


while your string concat version is not line by line


I’d imagine the way I should tackle it would be to capture text before the first carriage return and thrown away the first carriage return and subsequent characters? And using clojure.string/replace with the template <h1>$1</h1> would the the way?


something like

user=> (.replaceAll "foo\nbar" "(.+)" "<h1>$1</h1>")
might be closer


That sed does operate line by line, but finishes after line one - the expected answer is specifically just the fine line wrapped :thinking_face:


I say that with conviction because the book saids that the q stops sed after the first line - I’m learning sed passively to get through this book.


because it doesn’t have a /g. sed has some concise grammar for its programming language. It is far and beyond just regexes. note the s/../p that you have in your example are not valid regex constructs


Oh, right, I thought that might be the case.


I would reccomend finding the undergrad coursework for regular expressions


it makes the whole nightmare make a little more sense with that foundation


like, no language’s regexes are the academic regex

😢 1

this began from an oreilly book on regular expressions. I think the only thing needed is to remember the separation between a programming language that uses regexs and regexs themselves


Yeah, I want to focus on regex and not sed / perl, but I was advised this book was a less painful option 🤷


but thinking in terms of the academic version made things make a lot more sense, at least to me


Right, any specific coursework / resources?


More than you ever want to know about the various types of regex..


Thanks for the recommendation - I’ll have a browse around that site!


my class used Introduction to the Theory of Computation, 3rd edition


which you can probably find


Thanks, I’ll have a hunt


that’s gonna most likely start at nfa and dfa level. and go through things like pumping lemma. up to you if that’s the level you want or just regexs in practice


I think regexs in practice atm.


honestly i’d stay with the oreilly book then


So, if I do that, would you say my approach is sound; Capture characters before the first carriage return, and throw away the rest, and exploit the group in a replace?


Something like (clojure.string/replace #"(.*)\n[.*]" "foo\nbar", "<h1>$1</h1>)* - I know this won’t actually work


put the arguments in the right order and it works

user=> (clojure.string/replace "foo\nbar" #"(.*)\n.*" "<h1>$1</h1>")


but just work through the book. some thoughtful authors have spent a lot of time refining their teaching and coming up with examples


Oh, I forget the params are in a different order for replace than for re-seq etc. Oh good, I am learning! Yeah, I think sticking to the book and then applying it to Clojure would be a better bet. Cheers for the advice.


yeah. learn regexs. then use them in clojure. if you now regexs all you will need to do is consult for the features and particular dialect of Clojure’s regexs (which are just the native platform’s regexs)


What's the easiest way to log to file? (spit) ? Is there a easy to use logging library I can use that's like using spit ? I've looked at timbre, pedestal, tools.logging so far.


oh sweet summer child

😂 4

“Easy way to log in Java”


I guess I should've qualified that question with "preferable with no XML"


Yeah, there’s no easy way. I prefer tools.logging, but even that requires a fair amount of dependency management and XML.


Got it, I wanted to make sure that I wasn't missing something obvious


You can add-tap a fn that logs to a file.


Then use tap>


i think timbre has an “easy” way to do this and set up a file logger


so if you don’t want xml, this might be a fit for your needs.

👍 1

Like (add-tap #(spit "my-file" %))


tap can work. but it does have less flexibility than a proper logging setup. all taps are logs, no logging levels, etc.


@U07S8JGF7 I don't really know what tap is. I've been able to pretty easily spit to file. What does tap give you?


Tap will allow you to spit from multiple threads.


You don’t need it if you don’t ever spawn a thread (which is pretty rare, but does happen).


Oh and you want to do (spit "my-file" % :append true)


Ahh, that's good to know. I'm guessing timbre by default can handle logging to file with multiple theads?


Yes, any logging library can do that out of the box.


And like @U11BV7MTK said: the tap thing is easy. It’s not appropriate for production-level logging.


Ahh, that's good to know. about the spit option and logging libraries. I'll take a look at both. Thanks all!


The biggest things logging libraries give you which make them more prod-ready: 1. Control at a distance (you don’t need to change the log-emitting code to change the logging behavior) 2. Bounds / performance considerations. (eg. what to do when your disk can’t keep up)

🙌 1

@U02EA2T7FEH Thanks for the ulog link! Looks interesting!

Darin Douglass20:11:36

i love me some structured logging!


i have a bunch of bad URL data that i’m ingesting. urls are like “” “” and then some are just trash like “n/a”. anyone have a rec. on a library for dealing with this? ideally i’d like to validate and/or “fix” them to actually have a protocol, or throw them out if they’re nonsense.


You can try Unfortunately there is no method to check validity, but enough instruments to build validator yourself.


thanks. yeah, should have just looked to good ol’*


note: perfection is not required. there’s no way to know without actually making requests to know whether say http or https is correct for instance, but i’m looking for a basic normalization/validation step that’s a bit more robust than manually adding a protocol where it doesn’t exist, though as i type this, that may be sufficient for now


ah yes, forgot about the good folks and their lambda-shaped island. thank you.