Skip to content

Instantly share code, notes, and snippets.

@sbastn
Created January 19, 2011 02:38
Show Gist options
  • Save sbastn/785591 to your computer and use it in GitHub Desktop.
Save sbastn/785591 to your computer and use it in GitHub Desktop.
(ns dependency-mgmt.core
(:require [clojure.contrib.string :as str]))
(def classes "A B C
B C E")
(def deps (ref {}))
(defn build-dependency-map [seq]
(let [name (keyword (str (first seq)))
dependents (map keyword (str/split #"\s" seq))]
(dosync (alter deps assoc {:name name :deps (rest dependents)}))
))
(dosync (alter deps assoc :name "a" :deps "b"))
(str @deps)
(defn search [clazz dependency-map]
(let [name (dependency-map (keyword clazz) :name)
dependencies (dependency-map (keyword clazz) :deps)]
;; (swank.core/break)
(str name dependencies)))
(search :A (first (map build-dependency-map (str/split #"\n" classes))))
((first (map build-dependency-map (str/split #"\n" classes))) :name)
(map build-dependency-map (str/split #"\n" classes))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment