Changes between Version 46 and Version 47 of Clojure Client Tutorial


Ignore:
Timestamp:
Aug 8, 2011 2:39:55 PM (13 years ago)
Author:
kedwar10
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Clojure Client Tutorial

    v46 v47  
    427427
    428428=== Controlling Multiple Quagents ===
     429The simplest way to operate multiple quagents on the REPL is to wrap all commands with "future".
     430
     431{{{
     432client.core=> (future (move :bob 500 0))
     433#<core$future_call$reify__5508@12d7d02: :pending>
     434client.core=> (future (move :joe 500 0))
     435#<core$future_call$reify__5508@45ce17: :pending>
     436}}}
     437
     438If you want to apply the same command to many quagents, some typing can be saved with the "pmap" function, which is exactly like "map" except the elements are processed in parallel.
     439
     440{{{
     441client.core=> (pmap #(move % 1000 0) (get-quagents)) 
     442([] [])
     443}}}
     444
     445Similarly, the function "pcalls" can be used to execute no-arg functions in parallel.
     446
     447{{{
     448client.core=> (pcalls #(scan-area :bob 8000) #(move :joe 1500 180))
     449({"quagent_item_gold" ([839.970581 160.375198 0.613917] ... (output truncated)
     450client.core=> (pp)
     451({"quagent_item_gold"
     452  ([839.970581 160.375198 0.613917]
     453   [703.026123 110.582535 0.733509]
     454   [142.61908 136.43396 3.618063]),
     455  "quagent_item_treasure"
     456  ([493.463074 159.83313 1.045044] [908.39563 139.15329 0.567672]),
     457  "info_player_deathmatch"
     458  ([1001.049011 -176.454605 0.007154]
     459   [999.580505 -178.285645 0.007165]),
     460  "player" ([1005.275879 -174.131836 0.0] [30.128914 -90.0 0.0])}
     461 []) ; note that this is the data from the second command
     462nil
     463}}}
     464
     465Similarly, "pvalues" builds a lazy sequence of values.
     466
     467{{{
     468client.core=> (pvalues (scan-area :bob 8000) (move :joe 1500 180))           
     469({"quagent_item_gold" ([839.970581 160.375198 0.613917] ... (output truncated)
     470client.core=> (pp)
     471({"quagent_item_gold"
     472  ([839.970581 160.375198 0.613917]
     473   [703.026123 110.582535 0.733509]
     474   [142.61908 136.43396 3.618063]),
     475  "quagent_item_treasure"
     476  ([493.463074 159.83313 1.045044] [908.39563 139.15329 0.567672]),
     477  "info_player_deathmatch"
     478  ([1001.049011 -176.454605 0.007154]
     479   [999.580505 -178.285645 0.007165]),
     480  "player" ([1005.275879 -174.131836 0.0] [267.436554 -6.46857 0.0])}
     481 [])
     482nil
     483}}}
     484
     485
     486
    429487----
    430488