Oops, looking over gvec.clj it looks like I'm wrong about type-hinting fields. However you may need to type-hint the primitive array with a string instead of the symbol shorthand allowed by Clojure. Try the following:
^{:tag "[I" :unsynchronized-mutable true} David On Tue, Dec 18, 2012 at 1:46 PM, Vladimir Matveev <dpx.infin...@gmail.com>wrote: > Well, it is news for me since it is not documented anywhere. Why is this > so? BTW, typehinting value in '(let [value (aget data depth)]' binding > gives an error "Can't type hint a local with a primitive initializer" so I > think since this value considered primitive then I actually can hint the > fields to be primitive arrays. > Nonetheless, it does not look like that problem is in the field array: > wrapping aget form with (int) does not help. > > вторник, 18 декабря 2012 г., 17:46:14 UTC+4 пользователь David Nolen > написал: > >> I don't think you can type hint a field as a primitive array. >> >> On Tuesday, December 18, 2012, Vladimir Matveev wrote: >> >>> Hello, >>> >>> Consider the following code >>> >>> (gen-interface >>> :name IntStack >>> :methods [[stackPeek [] int] >>> [stackPush [int] void] >>> [stackPop [] int] >>> [stackDepth [] int]]) >>> >>> (deftype IntStackImpl >>> [^{:tag ints :unsynchronized-mutable true} data >>> ^{:tag int :unsynchronized-mutable true} depth] >>> IntStack >>> (stackPeek [this] >>> (aget data depth)) >>> (stackPush [this value] >>> (when (>= (inc depth) (alength data)) >>> (let [data-length (alength data) >>> new-data (int-array (* data-length 2))] >>> (System/arraycopy data 0 new-data 0 data-length) >>> (set! data new-data))) >>> (set! depth (inc depth)) >>> (aset data depth value)) >>> (stackPop [this] >>> (if (> depth 0) >>> (let [value (aget data depth)] >>> (set! depth (dec depth)) >>> value) >>> (throw (IllegalStateException. "Stack is already empty!")))) >>> (stackDepth [this] >>> depth)) >>> >>> This is very simple stack implementation over plain java array. It does >>> not compile with the following message: >>> CompilerException java.lang.VerifyError: (class: >>> clojure/data/xml/IntStackImpl, method: stackPop signature: ()I) Expecting >>> to find integer on stack >>> >>> However, when I replace the body of stackPop with, say, plain zero >>> literal 0, the method seems to pass the compilation, because then I'm >>> getting similar error on stackPush method instead. >>> Placing type hints inside stackPop method does not work (in fact, it is >>> even an error to place them, say, on value local binding). >>> >>> What am I doing wrong here? How to make the class compile? >>> >>> Cheers, >>> Vladimir. >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Clojure" group. >>> To post to this group, send email to clojure@googlegroups.com >>> Note that posts from new members are moderated - please be patient with >>> your first post. >>> To unsubscribe from this group, send email to >>> clojure+unsubscribe@**googlegroups.com >>> For more options, visit this group at >>> http://groups.google.com/**group/clojure?hl=en<http://groups.google.com/group/clojure?hl=en> >> >> -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en