On Jun 11, 12:16 pm, Daniel Lyons <fus...@storytotell.org> wrote:
> On Jun 11, 2009, at 9:25 AM, BerlinBrown wrote:
>
>
>
> > I do this a lot but can't figure out to change the UPDATEABLE_VALUE, I
> > am using some pseudo code because I don't have a clojure solution yet.
>
> > SET UPDATEABLE_VALUE = 0
> > (loop [line (.readLine reader)]
> >      (if (or (empty? line) (> line-num max-num))
> >       SET UPDATEABLE_VALUE = UPDATEABLE_VALUE + (SOME_FUNC)
> >        (recur (.readLine reader))))
>
> In general it's going to be something like this:
>
> (loop [line (.readLine reader) UPDATEABLE_VALUE 0]
>       (if (or (empty? line) (> line-num max-num))
>         (recur (.readLine reader) (+ UPDATEABLE_VALUE (SOME_FUNC)))))
>
> Whenever you would have modified a local variable before, in FP you
> establish a new binding instead.
>
> —
> Daniel Lyonshttp://www.storytotell.org-- Tell It!

I can modify the value within the loop, but what is a good approach
for accessing the value outside of the loop.  For example (pseudo code
with a mix of procedural logic).

;; Init updateable value outside of 'loop'
SET UPDATEABLE_VALUE = 0
 (loop [line (.readLine reader)]
      (if (or (empty? line) (> line-num max-num))
       SET UPDATEABLE_VALUE = UPDATEABLE_VALUE + (SOME_FUNC)
        (recur (.readLine reader))))
;; Now outside of the loop, use UPDATEABLE_VALUE with the mutated
value
(println UPDATEABLE_VALUE)



--~--~---------~--~----~------------~-------~--~----~
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 from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to