On Sunday, March 24, 2013 10:53:28 AM UTC+1, bsmith.occs wrote:
> Way back when I started with Clojure i was doing this:
>
> (let [constant-data (something-expensive)]
> (defn my-fn [x]
> (do-something-with x constant-data)))
>
> But was advised instead to do this:
>
> (def my-fn
> (let [c
Doug Hoyte's book "Let Over Lambda—50 Years of Lisp" devotes its very title
to the technique of (let...(fn...)).
On Friday, March 22, 2013 2:59:43 PM UTC-4, jamieorc wrote:
>
> Curious which style is preferred in Clojure and why:
>
> (defn f1 []
> (let [x {:foo 1 :bar 2 :baz 3}]
> (keys
Way back when I started with Clojure i was doing this:
(let [constant-data (something-expensive)]
(defn my-fn [x]
(do-something-with x constant-data)))
But was advised instead to do this:
(def my-fn
(let [constant-data (something-expensive)]
(fn [x]
(do-something-with x constan
On Sat, Mar 23, 2013 at 4:16 AM, Thomas Heller wrote:
> Just out of curiosity, does it have to be a function?
>
> (def data {:foo 1 :bar 2 :baz 3})
> (def data-keys (keys data))
>
> If one item is constant the other probably is too?
In this case, yes, but it's easy to imagine cases where neither
Just out of curiosity, does it have to be a function?
(def data {:foo 1 :bar 2 :baz 3})
(def data-keys (keys data))
If one item is constant the other probably is too?
Cheers,
/thomas
On Friday, March 22, 2013 7:59:43 PM UTC+1, jamieorc wrote:
>
> Curious which style is preferred in Clojure and
What if there's some computation in there, but such that should be
performed at compile time? I still prefer the outside let whenever I want
to make dead sure it's not getting reallocated on each call. If there was
some well-specified and easily understood guarantee (for example, like the
one J
The question should probably be asked: is there a benefit in a given
situation to having the let be outside the scope of the defn? I would argue
that most times it is not, and putting the let outside the function
clutters the code and makes it harder to see the functions defined in the
namespace. I
I've certainly seen this at least a few spots within the 4clojure codebase –
https://github.com/4clojure/4clojure/blob/develop/src/foreclojure/utils.clj#L66-L70
(quick example, I believe there are more)
On Friday, March 22, 2013 3:02:20 PM UTC-4, Jim foo.bar wrote:
>
> def/defn et. al are top-l
For the example given, I would say it depends on what you are trying to
express.
The function f1 is a function that needs some internal data x to operate
-x might be considered an implementation detail.
The function f2 operates on well known data x -x might be considered
configuration of f
Thanks, that's what I expected, especially after doing some (time... )
experiments.
On Friday, March 22, 2013 3:05:10 PM UTC-4, Laurent PETIT wrote:
>
>
> 2013/3/22 jamieorc >
>
>> Curious which style is preferred in Clojure and why:
>>
>> (defn f1 []
>> (let [x {:foo 1 :bar 2 :baz 3}]
>>
2013/3/22 jamieorc
> Curious which style is preferred in Clojure and why:
>
> (defn f1 []
> (let [x {:foo 1 :bar 2 :baz 3}]
> (keys x)))
>
> (let [x {:foo 1 :bar 2 :baz 3}]
> (defn f2 []
> (keys x)))
>
In either case, AFAIK, the compiler will recognize {:foo 1 :bar 2 :baz 3}
as const
def/defn et. al are top-level form definitions...very rarely (I'd say
never) you'd have a def/defn inside a 'let' or inside anything for that
matter...The 1st one looks good :)
Jim
On 22/03/13 18:59, jamieorc wrote:
Curious which style is preferred in Clojure and why:
(defn f1 []
(let [x
Curious which style is preferred in Clojure and why:
(defn f1 []
(let [x {:foo 1 :bar 2 :baz 3}]
(keys x)))
(let [x {:foo 1 :bar 2 :baz 3}]
(defn f2 []
(keys x)))
Cheers,
Jamie
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
T
13 matches
Mail list logo