Last active
December 30, 2015 19:29
-
-
Save frankhale/7874327 to your computer and use it in GitHub Desktop.
Can't figure out how to implement an interface in Clojure CLR
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
; This does not work, boo! Don't know how to tell Clojure that IsReusable is a property | |
(System.Reflection.Assembly/LoadWithPartialName "System.Web") | |
(defn foo-handler [] | |
(reify System.Web.IHttpHandler | |
(IsReusable [] false) | |
(ProcessRequest [context] ()))) |
This seems to work, at least the compiler doesn't complain:
user=> (def foo-handler
(reify System.Web.IHttpHandler
(get_IsReusable [this] false)
(ProcessRequest [this context] ())))
#'user/foo-handler
user=> (instance? System.Web.IHttpHandler foo-handler)
true
user=>
This is better and works fine in an ASP.NET app:
(deftype foo-handler []
System.Web.IHttpHandler
(get_IsReusable [this] false)
(ProcessRequest [this context]
(.Write (.Response context) "Hello, From Clojure CLR!")))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I haven't found much on Google for examples on implementing interfaces. I did find this one which is an example for Clojure JVM:
http://mylesmegyesi.blogspot.com/2011/12/implementing-java-interfaces-in-clojure.html