This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-25
Channels
@bbloom: I think that is inherited from Common Lisp, and perhaps inherited by choice because it is useful for having a final default value that can be an arbitrary value that is neither nil nor false.
andy.fingerhut: does common lisp even have a false boolean value? i thought it did not
I'd guess it's just consistency - if or
returns the first truthy form, then in case no form is truthy returning last tested form seems sensible. (or whatever false)
seems like a pretty neat trick though.
@bbloom: Having a final default value that is arbitrary is useful in both Common Lisp and CLojure.
Hmm, I'm aware of http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/*data-readers*, but how about function to write a custom tagged literal?
Hi How do I tell clojure I want a local binding resolved at compile-time (or only once, at least)?
(defn f [] 1)
(defn g []
(let [x (f)] ; result of f is a constant, call it only once, not every time I call g
x)
I am suprised it's not the deafault behaviour, most functions being pure and all that.No problem. Though it's rather unusual to use defn while closing something over. What's your use case?
The "constant" is a map of string to numbers. I could write the literal, but it is large and looks like magic. Instead I prefer to generate it programatically (clearer what it means that way), but it seems wasteful to do it everytime I call the function that uses it.
That would be an option as well (yeah, I don't want others to see it). Is that the idiomatic way? Your first solution seemed better at first glance, since it makes it clear that the binding is only used by that function.
Clojure records are more efficient than regular Clojure maps, especially when you have keys that stay the same So are transients of maps, especially when you have data that are private to one process and mutated very frequently. But Clojure currently does not support transients of records (http://dev.clojure.org/jira/browse/CLJ-1459). This means that people have to choose between records and transients; we cannot have both. If we need to store private state that both mutates very frequently (e.g., for the state of a stateful transducer) yet maintains the same keys, then should we, in general, use record volatiles or map transients?