2

我正在尝试访问原子地图中的地图。我有这个:

(def database (atom {:henk {:username "henk" :password "johnson" :session "test"}
:steve {:username "steve" :password "boldwin" :session "test2"}
:cane {:username "cane" :password "john" :session "test3"}}))

我试过使用交换!在 dosync 内部,但我似乎无法访问所需的值。你能帮助我吗?

4

1 回答 1

4
 user=> (def database (atom {:henk {:username "henk" :password "johnson" :session "test"}
                             :steve {:username "steve" :password "boldwin" :session "test2"}
                             :cane {:username "cane" :password "john" :session "test3"}}))
 #'user/database
 user=> (:henk @database)
 {:session "test", :username "henk", :password "johnson"}

修改:

user=> (swap! database assoc-in [:henk :session] "test + swap")
{:cane {:session "test3", :username "cane", :password "john"}, 
 :henk {:session "test + swap", :username "henk", :password "johnson"}, 
 :steve {:session "test2", :username "steve", :password "boldwin"}}

检查值是否已更新:

user=> @database
{:cane {:session "test3", :username "cane", :password "john"}, 
 :henk {:session "test + swap", :username "henk", :password "johnson"}, 
 :steve {:session "test2", :username "steve", :password "boldwin"}}
于 2013-01-09T11:45:40.307 回答