You can also memoize “expensive-calculation” …
https://clojuredocs.org/clojure.core/memoize
> On May 13, 2017, at 1:26 PM, Kevin Kleinfelter
> wrote:
>
> How would one convert the following procedural logic into functional/Clojure?
> x = expensive-calculation
> return (f1(x), f2(x), f
Yes, exactly. You can replicate what `def` and macros do using a regular
function and `intern`.
On Sat, May 13, 2017 at 4:04 PM, Timothy Baldridge
wrote:
> Okay, so I've read these SO articles about 4 times now, and I finally
> think I'm starting to understand what the `intern` solution is doing
Okay, so I've read these SO articles about 4 times now, and I finally think
I'm starting to understand what the `intern` solution is doing. I would
recommend this then can we simply state that:
`(def x 42)`
is equal to
`(intern 'x 42)`
Except the first is a compiler special form (and hence requ
I was just trying to answer a question posed by someone else, so I can't
give details about the original motivation. I thought it was a good example
of the capabilities of `intern` that I hadn't seen before, which could be
useful in a dynamic case where one wanted to generate functions on the fly
w
You are already doing exactly the right thing by having a temporary
variable.
To be precise a code fragment like:
(let [expensive-answer (some-fn x y z)
final-result { :k1 (f1 expensive-answer)
:k2 (f2 expensive-answer)
:k3 (f3 expensive-answer) }
Sorry, but this use of intern is a pointless. What does intern give you
that a let over a defn doesn't?
On Sat, May 13, 2017 at 4:37 PM, Alan Thompson wrote:
> If anyone is interested, I cleaned up the question to (hopefully) make it
> clearer, as well as adding the macro-calling-a-macro solutio
If anyone is interested, I cleaned up the question to (hopefully) make it
clearer, as well as adding the macro-calling-a-macro solution.
While some may consider it esoteric, I thought it was a good example of the
power `intern` can provide, as well as a good way to avoid macros and stick
to pure f
How would one convert the following procedural logic into
functional/Clojure?
x = expensive-calculation
return (f1(x), f2(x), f3(x))
I'm sure I could force it by using a var to save the intermediate value,
but that's still procedural. It seems like the pattern of reusing an
expensive r
Using a protocol is probably the optimal choice, since it also opens up the
dispatch allowing for extension without modifying exiting code. Downstream
users of your library can add extensions to your code without having to
create a patch.
On Sat, May 13, 2017 at 7:43 AM, Alex Miller wrote:
> O
Or case on (.getName the-class).
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe fro
10 matches
Mail list logo