changeset 26:bbffa41a12a9

moved apply-map to util.org from world.org, fixed some grammar problems, made examples more concise
author Robert McIntyre <rlm@mit.edu>
date Mon, 24 Oct 2011 05:41:50 -0700
parents 775d97247dd0
children 9ad188a327d3
files org/util.org org/world.org
diffstat 2 files changed, 29 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/util.org	Mon Oct 24 05:25:01 2011 -0700
     1.2 +++ b/org/util.org	Mon Oct 24 05:41:50 2011 -0700
     1.3 @@ -217,6 +217,16 @@
     1.4       (add-element game element (.getRootNode game))))
     1.5  
     1.6  
     1.7 +(defn apply-map
     1.8 +  "Like apply, but works for maps and functions that expect an
     1.9 +   implicit map and nothing else as in (fn [& {}]).
    1.10 +   ------- Example -------
    1.11 +   (defn demo [& {:keys [www] :or {www \"oh yeah\"} :as env}] 
    1.12 +     (println www))
    1.13 +   (apply-map demo {:www \"hello!\"})
    1.14 +   -->\"hello\""
    1.15 +  [fn m]
    1.16 +  (apply fn (reduce #(into %1 %2) [] m)))
    1.17  
    1.18  #+end_src
    1.19  
     2.1 --- a/org/world.org	Mon Oct 24 05:25:01 2011 -0700
     2.2 +++ b/org/world.org	Mon Oct 24 05:41:50 2011 -0700
     2.3 @@ -193,52 +193,32 @@
     2.4  :   fields with their names.  This helps with C wrappers where they have
     2.5  :   just defined a bunch of integer constants instead of enums
     2.6  
     2.7 +#+begin_src clojure :exports both :results verbatim
     2.8 +(take 5 (vals (pokemon.lpsolve/constant-map KeyInput)))
     2.9 +#+end_src
    2.10 +
    2.11 +#+results:
    2.12 +: ("KEY_ESCAPE" "KEY_1" "KEY_2" "KEY_3" "KEY_4")
    2.13 +
    2.14  =(all-keys)= converts the constant names like =KEY_J= to the more
    2.15  clojure-like =key-j=, and returns a map from these keys to
    2.16  jMonkeyEngine =KeyTrigger= objects, which jMonkeyEngine3 uses as it's
    2.17  abstraction over the physical keys. =all-keys= also adds the three
    2.18  mouse button controls to the map.
    2.19  
    2.20 -
    2.21  #+begin_src clojure :exports both :results output
    2.22  (require 'clojure.contrib.pprint)
    2.23  (clojure.contrib.pprint/pprint
    2.24 - (take 10 (keys (cortex.world/all-keys))))
    2.25 + (take 6 (cortex.world/all-keys)))
    2.26  #+end_src
    2.27  
    2.28  #+results:
    2.29 -#+begin_example
    2.30 -("key-n"
    2.31 - "key-apps"
    2.32 - "key-pgup"
    2.33 - "key-f8"
    2.34 - "key-o"
    2.35 - "key-at"
    2.36 - "key-f9"
    2.37 - "key-0"
    2.38 - "key-p"
    2.39 - "key-subtract")
    2.40 -#+end_example
    2.41 -
    2.42 -#+begin_src clojure :exports both :results output
    2.43 -(clojure.contrib.pprint/pprint
    2.44 - (take 10 (vals (cortex.world/all-keys))))
    2.45 -#+end_src
    2.46 -
    2.47 -#+results:
    2.48 -#+begin_example
    2.49 -(#<KeyTrigger com.jme3.input.controls.KeyTrigger@6ec21e52>
    2.50 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@a54d24d>
    2.51 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@1ba5e91b>
    2.52 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@296af9cb>
    2.53 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@2e3593ab>
    2.54 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@3f71d740>
    2.55 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@4aeacb4a>
    2.56 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@7cc88db2>
    2.57 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@52cee11e>
    2.58 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@c1da30b>)
    2.59 -#+end_example
    2.60 -
    2.61 +: (["key-n" #<KeyTrigger com.jme3.input.controls.KeyTrigger@9f9fec0>]
    2.62 +:  ["key-apps" #<KeyTrigger com.jme3.input.controls.KeyTrigger@28edbe7f>]
    2.63 +:  ["key-pgup" #<KeyTrigger com.jme3.input.controls.KeyTrigger@647fd33a>]
    2.64 +:  ["key-f8" #<KeyTrigger com.jme3.input.controls.KeyTrigger@24f97188>]
    2.65 +:  ["key-o" #<KeyTrigger com.jme3.input.controls.KeyTrigger@685c53ff>]
    2.66 +:  ["key-at" #<KeyTrigger com.jme3.input.controls.KeyTrigger@4c3e2e5f>])
    2.67  
    2.68  
    2.69  ** World Creation
    2.70 @@ -351,27 +331,15 @@
    2.71        ;; focus.
    2.72        (.setPauseOnLostFocus false)
    2.73        (.setSettings *app-settings*))))
    2.74 -
    2.75 -(defn apply-map
    2.76 -  "Like apply, but works for maps and functions that expect an
    2.77 -   implicit map and nothing else as in (fn [& {}]).
    2.78 -   ------- Example -------
    2.79 -   (defn demo [& {:keys [www] :or {www \"oh yeah\"} :as env}] 
    2.80 -     (println www))
    2.81 -   (apply-map demo {:www \"hello!\"})
    2.82 -   -->\"hello\""
    2.83 -  [fn m]
    2.84 -  (apply fn (reduce #(into %1 %2) [] m)))
    2.85 -
    2.86  #+end_src 
    2.87  
    2.88  
    2.89  =(world)= is the most important function here. It presents a more
    2.90 -functional interface to the Application life-cycle, and all it's
    2.91 -objects except =root-node= are plain clojure data structures. It's now
    2.92 -possible to extend functionally by composing multiple functions
    2.93 -together, and to add more keyboard-driven actions by combining clojure
    2.94 -maps.
    2.95 +functional interface to the Application life-cycle, and all its
    2.96 +arguments except =root-node= are plain immutable clojure data
    2.97 +structures. This makes it easier to extend functionally by composing
    2.98 +multiple functions together, and to add more keyboard-driven actions
    2.99 +by combining clojure maps.
   2.100  
   2.101  
   2.102