Changes between Version 40 and Version 41 of Clojure Client Tutorial
- Timestamp:
- Aug 8, 2011 11:54:29 AM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Clojure Client Tutorial
v40 v41 271 271 }}} 272 272 273 Partitioning these into a map is going to be a little more difficult as multiple positions will need to be stored at each key. However, we know already that the initial data structure to be a hash-map and the keys need to be the item type.273 Partitioning these into a map is going to be a little more difficult as multiple positions will need to be stored at each key. However, we know already that the initial data structure needs to be a hash-map and the keys need to be the item type. 274 274 275 275 {{{ … … 291 291 292 292 {{{ 293 client.core=> (send-and-get :Bob :radar :now [8000] {} (fn [prev [_ item-type & pos]] (merge-with concat prev {item-type (list pos)}))) 293 client.core=> (send-and-get :Bob :radar :now [8000] 294 {} 295 (fn [prev [_ item-type & pos]] 296 (merge-with concat prev {item-type (list pos)}))) 294 297 {"quagent_item_gold" (("375.085327" "56.309933" "1.374918") ... (output truncated) 295 298 client.core=> (pp) … … 310 313 }}} 311 314 315 These positions can't be used as strings, however, and will need to be converted to doubles. 316 317 {{{ 318 client.core=> (send-and-get :Bob :radar :now [8000] 319 {} 320 (fn [prev [_ item-type & pos]] 321 (merge-with concat 322 prev 323 {item-type (list (map #(Double/parseDouble %) 324 pos))}))) 325 {"quagent_item_gold" ((375.085327 56.309933 1.374918) (1019.278626 42.455196 0.505915) ... (output-truncated) 326 client.core=> (pp) 327 {"quagent_item_gold" 328 ((375.085327 56.309933 1.374918) 329 (1019.278626 42.455196 0.505915) 330 (905.141357 8.130102 0.569713)), 331 "quagent_item_treasure" 332 ((572.16864 20.462269 0.901278) (697.711304 63.434952 0.739097)), 333 "info_player_deathmatch" 334 ((32.000244 -90.0 0.223811) (0.125 0.0 90.0)), 335 "player" ((768.875366 90.065201 0.0) (32.0 -90.0 0.0))} 336 nil 337 338 }}} 339 312 340 313 341