Created
June 28, 2011 21:29
-
-
Save anonymous/1052284 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;------------------ | |
;;agent_sim.core.clj | |
;;------------------ | |
(ns agent_sim.core | |
(:gen-class) | |
(:use [agent_sim.config_handler :only [load-file]])) | |
(defn -main [& args] | |
;;config loading --> | |
(println "Loading config file/dir") | |
(load-file) | |
;;<-- config loading | |
;;starting sim --> | |
(println "Starting simulation") | |
;;<-- starting sim | |
;;ending sim --> | |
(println "Ending simulation") | |
;;<-- ending sim | |
) | |
;;------------------ | |
;;agent_sim.config_handler.clj | |
;;------------------ | |
(ns agent_sim.config_handler | |
(:use [clojure.contrib.duck-streams :only (read-lines)])) | |
;;refer to this for file reading: http://lethain.com/reading-file-in-clojure/ | |
(defn process-file [file-name line-func line-acc] | |
(reduce line-func line-acc (read-lines file-name))) | |
(defn process-line [acc line] | |
(reduce #(assoc %1 %2 (+ get %1 %2 0) 1) acc (.split line " "))) | |
(defn load-file | |
"Loads the config.json or [config] directory within the directory containing this file" | |
[] | |
(prn (process-file "config_handler.clj" process-line 0))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment