When I first looked at Clojure, I didn't get it (I scanned the docs
for 10 - 15 minutes).  A few month later, Stu Halloway said to give it
a second look and boy am I glad I did. Go read Stu's book, or at least
the first couple of chapters online at Manning.  Digest for a bit.
It'll be an eye opener.

On Fri, Oct 30, 2009 at 4:20 PM, David Nolen <dnolen.li...@gmail.com> wrote:
> On Fri, Oct 30, 2009 at 4:42 PM, Chick Corea <chick.zco...@gmail.com> wrote:
>>
>> Is everything in Clojure immutable?  For example, w/ this code-snippet
>>
>>       (let [x nil]
>>              ;; do something and modify 'x'
>>             )
>>
>> how does one modify the value of 'x' ?
>>
>>        (let [x nil] (def x true))
>>
>> this doesn't work.  the "def' interns and defines a (dynamic) root-
>> binding
>> for 'x' which is accessible outside the lexical closure.
>
> Welcome to functional programming :) Yes defs like that are generally looked
> down upon because all defs are top-level anyway.
>
>>
>> So I want to ask, am I in the minority in thinking that read-only
>> local bindings limit
>> the programmer a lot.  The only alternative that I see (w/ my limited
>> imagination)
>> is to create a "let" scope at the exact place that one needs it.  But,
>> IMO, that
>> sucks - sorry for the vernacular; but it is wildly inconvenient for me
>> for many reasons.
>
> That's the whole point of FP, referential transparency. With assignment you
> lose that. Clojure provides a great number of tools for dealing with FP
> style programming. If you really need mutability use a reference type- atom,
> ref.
> (def x (atom 0))
> (reset! x 1)
> @x -> 1
>
>>
>> Do both of these statements intern a symbol?  Or does the 2nd set the
>> currently
>> interned symbol to a new value ?
>>
>>      (def x 1)
>>      (def x 2)
>
> I believe this means:
> define a new var with the symbol 'x, bind it to the value 1.
> bind that var to the value 2.
> While it takes some time to get your head around the effect on programming
> style, you'll be pleasantly surprised when you decide to add concurrency
> into your program. Even if you don't, I think you'll find your programs
> generally easier to debug.
>
> >
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

--~--~---------~--~----~------------~-------~--~----~
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