Skip to content

Instantly share code, notes, and snippets.

@capitancook
Last active August 29, 2015 13:56
Show Gist options
  • Save capitancook/8913725 to your computer and use it in GitHub Desktop.
Save capitancook/8913725 to your computer and use it in GitHub Desktop.
Frame Language in Clojure - three basic functions
;; this gist contain the CLojure code for the blog post:
;; http://highorderdysfunctions.blogspot.it/2014/02/frame-language-in-clojure-part-1.html
(ns employees.core)
(def Henry {:is-a {:value 'system-analyst}
:working-at {:value 'unit-i}
:recruitment-date {:value "14/03/2010"}
:gross-salary {:value 3000,00}})
(defn fget [frame slot facet]
(get-in frame [slot facet]))
(defn fput [frame slot facet v]
(assoc-in frame [slot facet] v))
(defn fremove [frame slot facet]
(dissoc-in frame [slot facet]))
; dissoc-in was once part of clojure.contrib.core, and is now part of core.incubator
(defn dissoc-in
"Dissociates an entry from a nested associative structure returning a new
nested structure. keys is a sequence of keys. Any empty maps that result
will not be present in the new structure."
[m [k & ks :as keys]]
(if ks
(if-let [nextmap (get m k)]
(let [newmap (dissoc-in nextmap ks)]
(if (seq newmap)
(assoc m k newmap)
(dissoc m k)))
m)
(dissoc m k)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment