Skip to content

Instantly share code, notes, and snippets.

@tolitius
Created August 12, 2015 19:31
Show Gist options
  • Save tolitius/6642519d4ee9f6b0f819 to your computer and use it in GitHub Desktop.
Save tolitius/6642519d4ee9f6b0f819 to your computer and use it in GitHub Desktop.
(ns poco)
(gen-class
:name org.stargate.PlainOldClojureObject
:state "state"
:init "init"
:constructors {[Boolean Boolean String] []}
:methods [[isHuman [] Boolean]
[isFound [] Boolean]
[planet [] String]])
(defn -init [human? found? planet]
[[] (atom {:human? human?
:found? found?
:planet planet})])
(defn- get-field [this k]
(@(.state this) k))
(defn -isHuman [this]
(get-field this :human?))
(defn -isFound [this]
(get-field this :found?))
(defn -planet [this]
(get-field this :planet))
(defn -toString [this]
(str @(.state this)))
user=> (import '[org.stargate PlainOldClojureObject])
org.stargate.PlainOldClojureObject
user=> (def poco (PlainOldClojureObject. true true "42"))
#'user/poco
user=> poco
#object[org.stargate.PlainOldClojureObject 0x68033b90 "{:human? true, :found? true, :planet \"42\"}"]
user=> (.isHuman poco)
true
user=> (.isFound poco)
true
user=> (.planet poco)
"42"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment