When I write code in Java, I declare everything final that's possible
to be declared final, and I deliberately look for solutions that avoid
reassignment to variables, so all my variables are final).

I'm new to Clojure, so I might be wrong, but it seems that within a
function, mutable bindings must be explicitly created, either through
refs, atoms, or using the 'binding' form (or is it macro?).  That's
great, because within any lexical scope inside a function, I can
pretty much count on my bindings to never change.

However, outside the scope of a function, it seems that it's possible
for bindings to be redefined later in a file without causing an
immediate error.  This could easily lead to mistakes that would
manifest as silent and potentially inexplicable behavior later.

Mark

On Oct 2, 8:10 am, Meikel Brandmeyer <m...@kotka.de> wrote:
> Hi,
>
> On Oct 2, 4:29 pm, Mark <mjt0...@gmail.com> wrote:
>
> > Is there a way to make a declaration in Clojure that cannot be rebound
> > later?  Ideally, I'd like something that fails if I try to do this:
>
> > (def myname "mark")
> > ; ...more code, elided...
> > (def myname "Mark")
>
> > Perhaps this is obvious, but I see a lot of discussion of immutable
> > data structures, but I can't find a way to prevent my bindings from
> > changing.
>
> I'm not aware of such a feature. Putting {:macro true} in the metadata
> of the Var has this effect, but this is almost surely not what you
> want.
>
> Why do you need this functionality?
>
> Sincerely
> Meikel

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