Skip to content

Instantly share code, notes, and snippets.

@capitancook
capitancook / project.clj
Created December 30, 2014 09:27
project.clj used in this post
(defproject clj-fl-example "0.1.0"
:description "Human Resources Management System Use cases for the Frame Language library in CLojure.
Note that the project contains the dependencies necessary to be used with LightTable too"
:dependencies [[org.clojure/clojure "1.6.0"]
[clj-time "0.6.0"]
[clj-fl "0.1.0-prealfa10"]
[lein-light-nrepl "0.0.18"]
[adamclements/vijual "0.3.0-SNAPSHOT"]]
:repl-options {:nrepl-middleware [lighttable.nrepl.handler/lighttable-ops]})
@capitancook
capitancook / kb-hrms-1.clj
Created December 30, 2014 09:24
Knowledge base for my simple example of Frame based human esources management system described in this blog post
;-------------------------------------------Knowledge Base start------------------------------------------------
[
;------ Frame Language
{:frame {:value "frame"}
:description {:value "A frame is composed of one or more slots. Each frame represent a concept or a class of object or an object"}}
{:frame {:value "slot"}
:description {:value "One or more slots form a frame. Each slot represent a property or a feature of the frame"}}
(ns clj-fl-examples.renderlib
(:require [clj-fl.core :refer :all])
(import [java.awt Color]
[javax.imageio ImageIO]
[javax.swing JPanel JFrame]))
(def frame (atom nil))
(def gfx (atom nil))
[
;-------------------------------------------Knowledge Base start--------------------------------------------------
{:frame {:value "bu"}
:name {:value "Building Unit"}
:description {:value "A man-made structure with a roof and walls standing more or less permanently in one place. Can be composed of other building unit"}
:render2d {:proc render2dbu}
:showcofs {:proc showcofs}}
(ns clj-fl-examples.demons
(:require [clj-fl.core :refer :all]
[clj-fl-examples.renderlib :refer :all]))
(defn render2dbu [f]
(let [ims (fget f :cof :value)
namestr (fget f :name :value)]
(drawcolorstring
(list 0 0 255) namestr (fget f :sps :value))
(dorun (map #((resolve (fget-ii % :render2d :proc)) %) ims))))
[
;-------------------------------------------Knowledge Base start--------------------------------------------------
;------ AKO frames
{:frame {:value "bu"}
:name {:value "Building Unit"}
:description {:value "A man-made structure with a roof and walls standing more or less permanently in one place. Can be composed of other building unit"}
@capitancook
capitancook / showcofs.clj
Last active August 29, 2015 14:10
show the hierarchy :cof for a given frame f - published in the post http://highorderdysfunctions.blogspot.com
(defn showcofs
"show the hierarchy :cof for a given frame f"
[f]
(let [cofs (fget f :cof :value) cofslist (#(if-not (seq? %)(list %) %) cofs)] ;1
(if (nil? cofs)
(vector f) ;2
(reduce #( conj %1 ((if-let [showproc (fget-ii %2 :showcofs :proc)] (eval showproc) (vector %2)) %2)) (vector f) cofslist)))) ;3
;-------------------------------------------Knowledge Base start--------------------------------------------------
[
;------ AKO frames
{:frame {:value "bu"}
:name {:value "Building Unit"}
:description {:value "A man-made structure with a roof and walls standing more or less permanently in one place. Can be composed of other building unit"}}
@capitancook
capitancook / Frame-language-2.clj
Last active August 29, 2015 13:56
Clojure code described in
;; this gist contain the CLojure code for the blog post:
;; http://highorderdysfunctions.blogspot.it/2014/03/frame-language-in-clojure-part-2.html
;; Remember to include dependencies for [clj-time "0.6.0"] and [seesaw "1.4.4"] in your project file.
(ns employees.core)
(use 'seesaw.core)
(use 'clj-time.core)
(use 'clj-time.format)
(use 'clojure.test)
@capitancook
capitancook / Frame-language-1.clj
Last active August 29, 2015 13:56
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]