This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-25
Channels
For those using environ to manage environment variables during dev/prod, what do you use to pass a large number of properties when running your uberjar? Seems like there's no easy way to pass a file s.a., a .env
I usually use a mix of data defined in EDN files and then use ENV values to override these values in live running environments. You can bundle data files in the JARs and read them!
Environ can read from a Java Properties file (although the Environ project doesn't provide an example) The Java properties file could be used to define values for environment variables (although I advise against using any file secret and sensitive values) Other libraries that have application configuration use a file containing a hash-map, e.g donut-party/system, Integrant, etc.
Config usually goes in a resources directory and included on the project classpath, so those files are included when creating a jar
I have a Clojure expression that I want to execute only once when a specific function is called. I've tried using the ^:once
metadata tag as follows:
(^:once #(+ 4 2))
What is the correct way to ensure that a particular expression is executed only once within a Clojure function? Are there alternative approaches or best practices for achieving this? Or if my approach is correct?
Thanks 🙂Have you looked at delays? https://clojuredocs.org/clojure.core/delay
You could also look at memoization. Clojure includes a function for that https://clojuredocs.org/clojure.core/memoize which provides very little control as to how items get removed from it's cache. There's also https://github.com/clojure/core.memoize which will give you more control.
I don't think that the :once
metadata entry will do that https://ask.clojure.org/index.php/13050/what-does-once-meta-applied-for-anon-function-mean
defonce
??
Or update a value in an atom the first time the expression is called, surrounding by a check of the atom value each time the expression should be called, skipping if there is a value in the atom.
> I don't want to use delay to solve my problem
Could you explain why not? Using delay
is typically what folks use for "evaluate on-demand only once".
@U04V70XH6 Honestly, there is no specific reason. I just want to learn different approaches. I haven't used delay
before, so I'm not entirely sure about it(Because I am newbie in Clojure 🙂). If you advise that it's okay to use, then I will give it a try.
I read https://clojure.org/guides/spec and my takeaway is - wow, that's really cool, I want to use it everywhere. But then I look at Clojure code and see that it's used sparingly. Why is that? Are there guidelines for when to (not) use spec?
Rich talks about this in a couple of his presos. Specifically Spec-u-lation I think. The TL;DR is that Spec is good at the boundaries but is not needed "everywhere". During dev/test, you might use Spec more heavily (perhaps instrumenting functions during testing, generating test data, generative testing, etc), but for production usage you mostly use Spec around the edges of your code. Maybe this will help? https://corfield.org/blog/2019/09/13/using-spec/
Spec is also great for complex macros https://github.com/clyfe/clara-eav/blob/master/src/clara_eav/dsl.clj#L123-L126
The two sweet spots are information structures (keywords maps etc) and syntactic forms. The core specs focus on the latter, since the former is more typical in application domains