Actually, swap! doesn't seem to work in my case.    I should state
what I'm
trying to do.    I'm writing a graphics editing program where I want
the user
to be able to choose and save color values.   I start out with a
vector
containing blank and white.  When the user selects a new color and
wants
to save it I add the new color to the vector.

(def savedColors [black, white])
.....
(defn saveColor [color panel]
  (swap! savedColors  (conj savedColors color))   <-- this does not
work
  .....  also show the colors in the editor
))

I get the following error:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
clojure.lang.PersistentVector cannot be cast to clojure.lang.Atom

I assume I'm using swap! correctly, but may not be.

Bill

On Mar 23, 9:57 am, Per Vognsen <per.vogn...@gmail.com> wrote:
> By definition, persistent data structures are never mutable. But there
> are various kinds of mutable references (vars, refs, atoms, agents)
> that can _refer_ to persistent (hence unchanging) data structures.
>
> While David has given you an answer to your immediate query, I would
> ask you to step back and consider whether you're sure you really need
> references. You haven't supplied enough context for us to make that
> call.
>
> -Per
>
> On Tue, Mar 23, 2010 at 8:35 PM, WoodHacker <ramsa...@comcast.net> wrote:
> > I understand howconjworks.    But how do you add a value to a
> > persistent vector?    You have to add the new item to the vector with
> > (conjvector item), but how do you assign the return value to the
> > persistent vector.   So far I have it working with a def  -- (def
> > vector (conjvector item)) -- but I'm not sure this is 'pure'
> > Clojure.    Is there a better way, functionally, or am I there?
> > Functional programming is the best way to go, but very few programs
> > can exist without mutable persistent data.
>
> > Bill
>
> > --
> > 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
>
> > To unsubscribe from this group, send email to 
> > clojure+unsubscribegooglegroups.com or reply to this email with the words 
> > "REMOVE ME" as the subject.

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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to