Re: Changing value of atom vector using swap

2016-12-20 Thread Michael Blume
It doesn't look like data is actually an atom? Maybe that's just an error
in your e-mail...

On Tue, Dec 20, 2016 at 8:24 AM Ghadi Shayban  wrote:

> swap! takes as its arguments the atom and the function to transition the
> state inside the atom.  It implicitly calls the function on the state:
> (swap! data replace-value)
>
> It also can accept trailing arguments too...
>
>
> https://www.conj.io/store/v1/org.clojure/clojure/1.8.0/clj/clojure.core/swap%21
>
> On Tuesday, December 20, 2016 at 11:04:11 AM UTC-5, Rickesh Bedia wrote:
>
> I have
> (def data {:headers ["A" "B" "C" "D"]
>  :rows [["1" "2" "3" "4"] ["5" "6" "7" "8"] ["9" "10" "11"
> "12"]]})
>
> And I have a function
> (defn replace-value [struct]
> (clojure.walk/prewalk-replace {"3" "hello"} (struct :rows)))
>
> When I do
> (replace-value @data) > [["1" "2" "hello" "4"] ["5" "6" "7" "8"] ["9" "10"
> "11" "12"]]
>
> which is what I am expecting.
>
> However I want to achieve this same result using swap! So I tried
> #(swap! data (replace-value %))
>
> but I get the error #object[user$eval1308$fn__1309 0x6caeefd7
> "user$eval1308$fn__1309@6caeefd7"]
>
> I don't know what this error means nor how to resolve it
>
> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Changing value of atom vector using swap

2016-12-20 Thread Ghadi Shayban
swap! takes as its arguments the atom and the function to transition the 
state inside the atom.  It implicitly calls the function on the state:
(swap! data replace-value)

It also can accept trailing arguments too...  

https://www.conj.io/store/v1/org.clojure/clojure/1.8.0/clj/clojure.core/swap%21

On Tuesday, December 20, 2016 at 11:04:11 AM UTC-5, Rickesh Bedia wrote:
>
> I have
> (def data {:headers ["A" "B" "C" "D"]
>  :rows [["1" "2" "3" "4"] ["5" "6" "7" "8"] ["9" "10" "11" 
> "12"]]})
>
> And I have a function
> (defn replace-value [struct] 
> (clojure.walk/prewalk-replace {"3" "hello"} (struct :rows)))
>
> When I do
> (replace-value @data) > [["1" "2" "hello" "4"] ["5" "6" "7" "8"] ["9" "10" 
> "11" "12"]]
>
> which is what I am expecting.
>
> However I want to achieve this same result using swap! So I tried
> #(swap! data (replace-value %))
>
> but I get the error #object[user$eval1308$fn__1309 0x6caeefd7 
> "user$eval1308$fn__1309@6caeefd7"]
>
> I don't know what this error means nor how to resolve it
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Changing value of atom vector using swap

2016-12-20 Thread 'Rickesh Bedia' via Clojure
I have
(def data {:headers ["A" "B" "C" "D"]
 :rows [["1" "2" "3" "4"] ["5" "6" "7" "8"] ["9" "10" "11" 
"12"]]})

And I have a function
(defn replace-value [struct] 
(clojure.walk/prewalk-replace {"3" "hello"} (struct :rows)))

When I do
(replace-value @data) > [["1" "2" "hello" "4"] ["5" "6" "7" "8"] ["9" "10" 
"11" "12"]]

which is what I am expecting.

However I want to achieve this same result using swap! So I tried
#(swap! data (replace-value %))

but I get the error #object[user$eval1308$fn__1309 0x6caeefd7 
"user$eval1308$fn__1309@6caeefd7"]

I don't know what this error means nor how to resolve it

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.