Runtime Constants & Static Variables #3182
-
In other languages, there is the concept of runtime constants or static variables which can get initialized once and then just sit there for the life of the program. I was wondering if this was possible in Gleam. I'm working my way through the Exercism course right now and I started reaching for that behavior when working with regexes. Normally in other languages I'd cache the compiled regex in a constant to make sure that it doesn't get recreated each time it gets used. The only alternatives I've been able to find is either creating it early on in the program and passing it around or caching it in some other instantiated type which will end up using it from time to time. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Gleam does not have any of those features, no. You could choose to pass it in as an argument or you could use functionality such as persistent term or ETS to store it in a way that you can access non-locally. |
Beta Was this translation helpful? Give feedback.
Gleam does not have any of those features, no.
You could choose to pass it in as an argument or you could use functionality such as persistent term or ETS to store it in a way that you can access non-locally.