Re: Mutable local variables

2014-11-12 Thread John Gabriele
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

Re: Mutable local variables

2014-11-10 Thread Ashton Kemerling
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

Re: Mutable local variables

2014-11-10 Thread Gary Trakhman
@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

Re: Mutable local variables

2014-11-10 Thread Jacob Goodson
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

Re: Mutable local variables

2014-11-10 Thread Thomas Heller
@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-

Re: Mutable local variables

2014-11-09 Thread Jacob Goodson
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

Re: Mutable local variables

2014-11-08 Thread Fluid Dynamics
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

Re: Mutable local variables

2014-11-08 Thread Andy Fingerhut
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

Re: Mutable local variables

2014-11-08 Thread Timothy Baldridge
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

Re: Mutable local variables

2014-11-08 Thread Alan Dipert
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

Mutable local variables

2014-11-08 Thread Blake McBride
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