This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-30
Channels
- # adventofcode (95)
- # announcements (17)
- # babashka (28)
- # beginners (107)
- # calva (34)
- # clj-kondo (7)
- # cljs-dev (20)
- # cljsrn (1)
- # clojure (95)
- # clojure-europe (41)
- # clojure-italy (3)
- # clojure-nl (5)
- # clojure-spec (7)
- # clojure-uk (4)
- # clojurescript (77)
- # cursive (7)
- # data-science (1)
- # datalog (4)
- # datomic (12)
- # events (3)
- # fulcro (32)
- # graalvm (2)
- # hugsql (19)
- # introduce-yourself (4)
- # jobs (2)
- # lsp (20)
- # membrane-term (19)
- # numerical-computing (1)
- # off-topic (8)
- # pathom (3)
- # polylith (17)
- # portal (42)
- # re-frame (7)
- # reagent (32)
- # remote-jobs (1)
- # shadow-cljs (86)
- # spacemacs (3)
- # tools-deps (52)
- # uncomplicate (1)
- # xtdb (23)
Does anyone have an opinion on translation/internationalization libraries like Pottery, Tempura or Tongue?
Is there a word (or a predicate) for a thing that is a coll?
but not a map? I guess not?
sequential?
does not include sets, but that's the most often thing I use narrower than coll
well, no name for that
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.
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
"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?
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)
Exactly!!
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
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>")
"<h1>foo</h1>\n<h1>bar</h1>"
user=>
might be closerThat 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.
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?
I always have to refer to this : https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/regex/Pattern.html
More than you ever want to know about the various types of regex..https://www.regular-expressions.info/
Thanks for the recommendation - I’ll have a browse around that site!
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.
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>")
"<h1>foo</h1>"
user=>
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 https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html 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.
Yeah, there’s no easy way. I prefer tools.logging, but even that requires a fair amount of dependency management and XML.
so if you don’t want xml, this might be a fit for your needs. https://github.com/ptaoussanis/timbre#basic-file-appender
https://github.com/BrunoBonacci/mulog/blob/master/doc/publishers/simple-file-publisher.md ^ if you wanted to go the structured logging route
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?
You don’t need it if you don’t ever spawn a thread (which is pretty rare, but does happen).
Ahh, that's good to know. I'm guessing timbre by default can handle logging to file with multiple theads?
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)
@U02EA2T7FEH Thanks for the ulog link! Looks interesting!
i love me some structured logging!
i have a bunch of bad URL data that i’m ingesting. urls are like “http://example.com/foo” “http://www.example.com/” 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 https://docs.oracle.com/javase/7/docs/api/java/net/URL.html Unfortunately there is no method to check validity, but enough instruments to build validator yourself.
thanks. yeah, should have just looked to good ol’ http://java.net.*
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
https://github.com/michaelklishin/urly might be useful or possibly https://github.com/lambdaisland/uri