clojure-europe

For people in Europe... or elsewhere... UGT https://indieweb.org/Universal_Greeting_Time
slipset 2020-12-10T06:37:25.183900Z

Morning. December is really showing itself from its worst side this year. Dark and grey every day.

orestis 2020-12-10T07:11:29.187200Z

Yeah it’s not helping with the 2020 blues. Gray and cold and dark and wet here in Copenhagen

slipset 2020-12-10T07:12:21.188100Z

One of the things I enjoy the least with maintaining OSS is the actual release process. The pains involve updating a bunch of files with the correct version, especially random version strings in Readmes and tagging, How do you manage these things?

orestis 2020-12-10T07:17:28.189200Z

I still have Reseda under just a git sha because I can’t be bothered to figure out Clojars and bundling Cljs stuff.

orestis 2020-12-10T07:17:51.189800Z

I think you can do something like this in a GitHub action?

javahippie 2020-12-10T07:24:09.190Z

Morning!

javahippie 2020-12-10T07:26:30.191200Z

In comparison to Javas public Maven Repo, releasing to Clojars is “relatively” simple and straightforward, but I still have to google every time what the steps were.

javahippie 2020-12-10T07:26:48.191700Z

@orestis do you want the GitHub Action to do the bundling, or also the “pushing to Clojars” part?

dharrigan 2020-12-10T07:39:42.192Z

Good Morning!

dominicm 2020-12-10T07:42:29.192200Z

Morning

orestis 2020-12-10T07:58:37.194900Z

@javahippie I’ve no clue, haven’t thought about it! We’re using a GitHub action for doing releases of our software on elastic beanstalk on AWS, and the pattern there is that on every commit to master it will run a build and upload an artifact to S3, but the deployment action is meant to be run on purpose by a human.

orestis 2020-12-10T07:58:54.195500Z

It works well but I’m not sure how it would apply to Clojars etc.

ordnungswidrig 2020-12-10T07:59:56.196600Z

Good morning!

javahippie 2020-12-10T08:00:05.196900Z

If your environment variables are right, you could push to Clojars with a leiningen plugin in the action. But I am too paranoid to store my Clojars Credentials in GitHub, so I release manually every time

ordnungswidrig 2020-12-10T08:02:08.198500Z

Updating the Readme should include more than the version (otherwise no reason for a release, right?). For the reference to the latest version on clojar I used the embedded SVG which is nasty but maybe the best you can do? When it comes to published documentation you can used a preprocessor of any kind to do text replacement in the most simple case.

synthomat 2020-12-10T08:04:24.198700Z

good morning!

simongray 2020-12-10T08:23:15.198900Z

good morning

simongray 2020-12-10T08:25:16.199400Z

@orestis I feel ya. Supposedly it’ll be like this the rest of the year.

simongray 2020-12-10T08:25:31.199700Z

the weather, I mean.

plexus 2020-12-10T08:29:53.199900Z

Good morning!

slipset 2020-12-10T08:39:04.202300Z

@ordnungswidrig re updating the readme, that kind’a depends I guess. If your current version is 1.2.3-SNAPSHOT, then I guess you can let PR’s update the readme with any new functionality you need/want to document. And then on release you change the version to 1.2.3 , publish, and update the version to 1.2.4-SNAPSHOT (not that I’m doing that).

slipset 2020-12-10T08:39:26.202800Z

Also, one could imagine that more finegrained docs live other places than in the readme.

thomas 2020-12-10T08:39:31.203Z

morning lovely people!

slipset 2020-12-10T08:39:44.203300Z

morning @thomas

👋 1
slipset 2020-12-10T08:40:26.203900Z

Had a lovely start today with 45 mins of the Defn podcast on my ears while on my ballance rollers.

😂 1
plexus 2020-12-10T09:06:36.205300Z

For the lambda island libraries we update anything that looks like a deps.edn or leiningen version vector/map for the current project to the version number that is being released, and commit that before the release. This way it always shows the most recently released version on github, and it shows the version you are looking at in cljdoc.

plexus 2020-12-10T09:08:08.205700Z

https://github.com/lambdaisland/open-source/blob/master/src/lioss/release.clj <-- code to do that lives here

ordnungswidrig 2020-12-10T09:47:11.206800Z

That’s neat. But honestly the need for prgrammatic creation of a regex is on the edge of what I consider to be comfortable with 😛

ordnungswidrig 2020-12-10T09:47:49.207100Z

These are the dirty secrets of our industry I guess.

2020-12-10T09:57:14.207300Z

morning

borkdude 2020-12-10T10:06:51.207700Z

@ordnungswidrig Are you talking about regal in general?

plexus 2020-12-10T10:07:42.208900Z

I think in this case I could have still quite easily written these regexes directly. It would be a lot more concise but harder to maintain.

borkdude 2020-12-10T10:08:16.209900Z

I think the idea of regal is pretty great. For perf reasons I would probably generate the regexes in a REPL session and then inline them manually. They don't need to be evaluated each time I run my code. But I will keep the original regal expression around because it's way more readable.

ordnungswidrig 2020-12-10T10:08:16.210Z

@borkdude no, but the need to construct regexes is always kind of edgy, isn’t it?

ordnungswidrig 2020-12-10T10:08:47.210500Z

I mean regex as data compared to regex as a dsl (“actual regexes” 🙂 🤷

plexus 2020-12-10T10:10:52.211100Z

This is what that regex compiles to

#"lambdaisland/kaocha(\s+\{\s*:mvn/version\s+\")[^\"]+(\"\s*\})"

plexus 2020-12-10T10:11:20.211600Z

not sure what you're saying @ordnungswidrig? would you consider regex in general a smell or red flag?

ordnungswidrig 2020-12-10T10:16:12.213200Z

well, regex are fine (unless you’re trying to parse HTML with it). But constructing regex via something like regal should be kind of a last resort when you really need it. I think the actual string regex representation is fine and way more readable in almost any case.

borkdude 2020-12-10T10:17:35.213800Z

How is one giant string more readable than information around each sub-string?

borkdude 2020-12-10T10:18:19.214400Z

btw, there are also parser combinator libraries for clojure that let you parse strings with good performance, similar to spec (but then designed for actual text)

borkdude 2020-12-10T10:31:03.215500Z

btw, I have also created documented regexes by just giving names to each sub-part and then using re-pattern and str to create it, just for readability. or little functions to create the sub-parts based on some dynamic input

ordnungswidrig 2020-12-10T10:37:24.217200Z

Yeah, I’ve used that before and I totally see the use case for “AST”-based regex creation. But for the daily simpler cases foo-bar: (\d+)-(\w+) I strongly prefer the string over a clojure reresentation of it. 😉

plexus 2020-12-10T10:49:33.218600Z

I'm quite comfortable writing plain old regex so I don't use regal myself that often. Regal came about when I was working on this: https://github.com/lambdaisland/trikl/blob/trikl1/src/lambdaisland/trikl1/specs.clj here the benefits are multiple, I can define each sub section separately, can validate subparts as well as the combined versions, and I can generate each as needed in my tests

raymcdermott 2020-12-10T11:23:41.219100Z

morning

☀️ 2
simongray 2020-12-10T11:32:40.222900Z

Regular string regex would be perfect for 99.9% of use cases if whitespace was ignored when compiling the pattern the same way it’s ignored in pretty much every other compiled language. The syntax is simple and easy to grasp. The only real problem is that fact that there is no obvious way to semantically partition the patterns you write when spaces are considered part of the pattern.

borkdude 2020-12-10T11:33:16.223200Z

string concat + re-pattern

simongray 2020-12-10T11:34:04.223700Z

I guess, but then you lose out on the niceties of regex literals

borkdude 2020-12-10T11:34:40.224Z

#=(re-pattern (str ....)) 👿

simongray 2020-12-10T11:35:14.224800Z

not good enough

simongray 2020-12-10T11:37:33.226900Z

regex literals are great because they are different from strings and this can be reflected in syntax highlighting and the quality of life feature of not having to double escape a bunch of stuff (another common issue with regex readability).

simongray 2020-12-10T11:38:19.227800Z

I guess with a suitably clever macro you can accomplish many great things, but it would be a lot nicer to just be able to ignore whitespace…

borkdude 2020-12-10T11:40:14.228300Z

it seems the only escaping that happens is for backslashes: https://github.com/clojure/tools.reader/blob/99c627f74f9f99bebe69ddb3c0044b322f59f3fb/src/main/clojure/clojure/tools/reader.clj#L94

simongray 2020-12-10T11:41:24.229700Z

Yeah, in regex in many other languages you have to double escape every escaped character like \s \n \t etc.

plexus 2020-12-10T11:41:35.230100Z

Ruby has a modifier for ignoring whitespace

/regex
some more regex
.../x

simongray 2020-12-10T11:41:51.230400Z

hm, if Ruby can have it why can’t we!?

plexus 2020-12-10T11:43:40.230900Z

Turns out we do!

(re-find #"(?x) hello world" "helloworld")

🕺 2
🎉 4
plexus 2020-12-10T11:44:13.231500Z

who knew?? 😄

simongray 2020-12-10T11:44:22.231700Z

oooooh! well, then I was grumpy for nothing

borkdude 2020-12-10T11:44:39.232Z

Very simple solution:

(require '[clojure.string :as str])

(defn regex [&amp; parts]
  (-&gt; (str/join parts)
      (re-pattern)))

(def re (regex #"\w+" #"bar"))

(prn re)

(prn (re-matches re "foobar"))

borkdude 2020-12-10T11:46:11.232700Z

This now allows you to document each part:

(def re (regex #"\w+" ;; match leading char
               #"bar" ;; match bar
               ))

❤️ 1
borkdude 2020-12-10T11:46:20.232900Z

with still syntax highlighting

simongray 2020-12-10T11:47:18.233900Z

that’s actually pretty good too since it allows comments, but I think my personal preference would just be using that x flag

borkdude 2020-12-10T11:47:35.234200Z

I think Java regexes also allow comments.

borkdude 2020-12-10T11:47:55.234400Z

(?#comment)

simongray 2020-12-10T11:48:14.234600Z

hm interesting

simongray 2020-12-10T11:48:49.235100Z

well, that was a mind-expanding 10 minutes on this channel 🙂

borkdude 2020-12-10T11:51:10.235900Z

I haven't been able to figure out a working example though ;)

slipset 2020-12-10T11:58:05.236300Z

The wonders of #clojure-europe 🙂

ordnungswidrig 2020-12-10T15:15:04.238200Z

Advanced regexes are advanced. “Lookbehind Zero-Length Assertions” is burned into my memory from my times as a perl developer

ordnungswidrig 2020-12-10T15:15:38.238600Z

> (?&lt;!a)b matches a “b” that is not preceded by an “a”, using negative lookbehind.

ordnungswidrig 2020-12-10T15:15:45.238800Z

That can become handy.

ordnungswidrig 2020-12-10T15:17:36.239200Z

Also forward references are neat: > If forward references are supported, the regex (\2two|(one))+ matches oneonetwo.

ordnungswidrig 2020-12-10T15:17:51.239600Z

But honestly I would not know by heard what of this funky stully is supported by Java.

dominicm 2020-12-10T16:18:25.240400Z

Java's regex is very powerful, and it has 2 engines with different performance characteristics dependent on your regex.

ordnungswidrig 2020-12-10T18:18:40.240600Z

I didn’t know that.

plexus 2020-12-10T20:04:12.242400Z

Yeah pro tip if you're looking for the docs on Clojure regexes, look for the javadoc for Pattern. Very comprehensive! https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/regex/Pattern.html

✔️ 4