On Saturday, November 8, 2014 10:15:12 PM UTC-5, Blake McBride wrote:
>
> Greetings,
>
> I have a sense that there is value in immutable variables and data but
> that value is unneeded in my application and more than a nuisance. How can
> I create a "let" that creates mutable locals that I can e
Mutation is not a bad performance optimization, and is super useful when the
algorithm in question just works better with it.
--Ashton
Sent from my iPhone
> On Nov 10, 2014, at 11:11 AM, Jacob Goodson
> wrote:
>
> I like the map suggestion but there are still those times when mutation makes
@Jacob, your specific use-case is much cleaner with cond-let:
http://crossclj.info/fun/flatland.useful.experimental/cond-let.html
Example:
(cond-let [b (bar 1 2 3)] (println :bar b)
[f (foo 3 4 5)] (println :foo f)
[b (baz 6 7 8)] (println :baz b)
:else
I like the map suggestion but there are still those times when mutation
makes for a cleaner hack(imo of course).
On Monday, November 10, 2014 5:44:25 AM UTC-5, Thomas Heller wrote:
>
> @Jacob: If you get too many arguments in a loop I found it best to use a
> map.
>
> (loop [{:keys [a b c] :as s
@Jacob: If you get too many arguments in a loop I found it best to use a
map.
(loop [{:keys [a b c] :as state} a-map]
(cond
(and (= a 1) (= b 2))
(recur (update state :a inc)) ;; 1.7+ only, otherwise use update-in
...))
Working with named arguments (vs. positional) is a lot more user-
Sometimes, when writing code that loops with a good bit of branching, it
can be quite annoying to stay immutable.
(loop [way 1
too 2
many 3
args 4
makes 5
things 6
annoying 7]
(cond (and (= way
I wonder if the OP is aware that you can rebind the same name multiple
times in a let. For instance
(let [x something
y otherthing
x (if (pred? x y) x (some-func x y))
x (further (complex (calculations x)))
...]
(do-something-with x))
No actual mutability, but most of t
In addition to the other suggestions, Clojure's with-local-vars may suit
your needs: http://clojuredocs.org/clojure.core/with-local-vars
On Sat, Nov 8, 2014 at 7:15 PM, Blake McBride wrote:
> Greetings,
>
> I have a sense that there is value in immutable variables and data but
> that value is un
Clojure itself uses volatiles (added in 1.7) for this sort of thing.
http://dev.clojure.org/jira/browse/CLJ-1512
On Sat, Nov 8, 2014 at 8:37 PM, Alan Dipert wrote:
> Blake, https://github.com/ztellman/proteus would be something to look at.
> Alan
>
>
> On Saturday, November 8, 2014 10:15:12 PM U
Blake, https://github.com/ztellman/proteus would be something to look at.
Alan
On Saturday, November 8, 2014 10:15:12 PM UTC-5, Blake McBride wrote:
>
> Greetings,
>
> I have a sense that there is value in immutable variables and data but
> that value is unneeded in my application and more than a
Greetings,
I have a sense that there is value in immutable variables and data but that
value is unneeded in my application and more than a nuisance. How can I
create a "let" that creates mutable locals that I can easily get the value
from and set a new value? Presumably, I can hide the mess i
11 matches
Mail list logo