On Monday, February 13, 2023 at 7:08:35 PM UTC-5 David Finkel wrote:
So, why can't the regexp be a constant?
 Only primitive types are allowed to be constant in go 
<https://go.dev/ref/spec#Constants>

Oh, this is what I missed.

For cases like this, I tend to create an unexported package variable that's 
initialized with MustCompile.
package-level variables are generally bad-form, but there are cases where 
you have mostly-readonly things that must be initialized at startup in 
which they make sense. (constant-initialized regexps are one of these)

Which is why I was trying to not use them or make things const.

Long ago, when dinosaurs roamed, I spent a lot of time trying to use C++'s 
const
in places that made sense. It was a disaster and I gave up.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/58c0112c-e797-4b64-aa9c-9826b423bc60n%40googlegroups.com.

Reply via email to