No, you shouldn't worry about that) In fact it was useful to me to learn that Clojure does not support array type hints everywhere. It may be possible that I will have to change some of my code because of this.
вторник, 18 декабря 2012 г., 23:30:39 UTC+4 пользователь David Nolen написал: > > Ah right, sorry to mislead. > > > On Tue, Dec 18, 2012 at 2:26 PM, Vladimir Matveev > <dpx.in...@gmail.com<javascript:> > > wrote: > >> Thanks, but it seems that I have found the source of problem, though I do >> not know why compiler message is so uninformative and misleading. >> >> The following code does not work (fails with CompilerException >> java.lang.VerifyError: (class: test/Test2Impl, method: fail signature: ()V) >> Expecting to find integer on stack): >> >> (definterface Test2 >> (^void fail [])) >> >> (deftype Test2Impl >> [^{:unsynchronized-mutable true :tag int} x] >> Test2 >> (fail [this] >> (set! x (dec x)))) >> >> The following code _does_ work: >> >> (definterface Test2 >> (^void fail [])) >> >> (deftype Test2Impl >> [^{:unsynchronized-mutable true :tag int} x] >> Test2 >> (fail [this] >> (set! x (int (dec x))))) >> >> Note that I have wrapped (dec x) into (int). This compiles and works >> flawlessy. >> >> In fact it is fine that there is an error here because (dec) is defined >> only on objects and longs, so supplying int to it does not work as >> intended. Even my first example in this message will work if you replace >> :tag int with :tag long. >> However, error message is absolutely misleading and seems to be a >> consequence of an error in the compiler... >> >> >> >> вторник, 18 декабря 2012 г., 23:18:28 UTC+4 пользователь David Nolen >> написал: >>> >>> 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.in...@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@**googlegrou**ps.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 clo...@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+u...@**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 clo...@googlegroups.com<javascript:> >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> clojure+u...@googlegroups.com <javascript:> >> 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