Created
September 10, 2015 22:03
-
-
Save puredanger/9cc4304a43de9a67171b to your computer and use it in GitHub Desktop.
Example of using gen-class to subclass a class with multi-arity method
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
(ns example.ByteInputStream | |
(:gen-class | |
:extends java.io.InputStream | |
:state byteseq | |
:init init | |
:constructors {[clojure.lang.Seqable] []} | |
:exposes-methods {read readSuper} | |
:main false)) | |
(defn -init [byte-seq] | |
[[] (ref byte-seq)]) | |
(defn -read | |
([this] (dosync | |
(let [byte-seq (.byteseq this) | |
[b & more-bytes] @byte-seq] | |
(ref-set byte-seq more-bytes) | |
(if b b -1)))) | |
([this byte-arr] (.readSuper this byte-arr)) | |
([this byte-arr off len] (.readSuper this byte-arr off len))) | |
(comment | |
(compile 'example.ByteInputStream) | |
(def bis (example.ByteInputStream. [67 108 111 106 117 114 101])) | |
(slurp bis) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment