I'm trying to translate some Common Lisp code into Scheme code. The Common Lisp code has a deftype. Are deftypes in Scheme the same as deftypes in Common Lisp? How do you translate a deftype in Common Lisp into equivalent code in Scheme?
...
In clojure, how do I type type hint a type that I have created? (I want to nest the types.)
e.g. I had thought that this would work:
(deftype A
[#^somePrimitive someField])
(deftype B
[#^A Avalue])
This brings up an error message:
Unknown location:
error: java.lang.ClassNotFoundException: A
Note: clojure types are a...
Yesterday, Rich pulled the 'new' branch of Clojure into master. We are now embracing the beauty that is deftype and defprotocol. Of course, I, coming from Haskell, am very tempted to define types like I would in Haskell, which would be for virtually everything short of a throwaway tuple, but I don't think it works like that in Clojure wo...
Clojure structs can be arbitrarily extended, adding new fields.
Is it possible to extend types (created using deftype) in a similar way?
EDIT: For the benefit future visitors, as Brian pointed out below, this feature is subject to change.
...
I'm attempting to use deftype (from the bleeding-edge clojure 1.2 branch) to create a java class that implements the java Servlet interface. I would expect the code below to compile (even though it's not very useful).
(ns foo [:import [javax.servlet Servlet ServletRequest ServletResponse]])
(deftype servlet []
javax.servlet.Servle...
I'm trying to create a new type in Clojure using deftype to implement a two dimensional (x,y) coordinate, which implements a "Location" protocol.
I'd also like to have this implement the standard Java equals, hashCode and toString methods.
My initial attempt is:
(defprotocol Location
(get-x [p])
(get-y [p])
(add [p q...
I'm trying out Clojure 1.2, specifically mutable fields which are supported in deftype according to the clojure.org documentation.
But I can't get the set to work. What is the syntax for updating a field? Or isn't mutability implemented yet?
(definterface IPoint
(getX [])
(setX [v]))
(deftype Point [x]
IPoint
(getX [this] x)
...
I am trying to use clojure in a compiler and thus need to parameterize calls to deftype; however, I am having difficulty making the type hints carry through. Consider the following code:
(defn describe [x]
(let [fields (.getDeclaredFields x)
names (map #(.getName %) fields)
types (map #(.getType %) fields)]
(inte...
(deftype Bag [state]
Object
(toString [bag]
(str "Bag???" state)))
I want the toString to look something like
clojure.core=> (def b (Bag. {:apples 1 :bannanas 4}))
#'clojure.core/b
clojure.core=> (str b)
"BAG: {:apples 1 :bannanas 4}"
What is a nice clojurey way of representing that information?
Is
"Bag/{:k :v}"
...
I have a project set up with leiningen called techne. I created a module called scrub with a type in it called Scrub and a function called foo.
techne/scrub.clj:
(ns techne.scrub)
(deftype Scrub [state]
Object
(toString [this]
(str "SCRUB: " state)))
(defn foo
[item]
(Scrub. "foo")
"bar")
techne/scrub_test.clj...