On Sun, Jan 30, 2011 at 8:39 PM, Ken Wesson <kwess...@gmail.com> wrote:
> On Sun, Jan 30, 2011 at 1:35 PM, Jonas Enlund <jonas.enl...@gmail.com> wrote:
>> On Sun, Jan 30, 2011 at 7:01 PM, Ken Wesson <kwess...@gmail.com> wrote:
>>> On Sun, Jan 30, 2011 at 9:26 AM, Jonas Enlund <jonas.enl...@gmail.com> 
>>> wrote:
>>>> Hi.
>>>> I'm trying to create a java.io.Writer proxy (which writes to a
>>>> JTextArea) but I can't get it to work.
>>>> Here is my clojure code so far:
>>>>
>>>> (def text-area (javax.swing.JTextArea.))
>>>>
>>>> (def frame
>>>>      (let [f (javax.swing.JFrame.)]
>>>>        (.. f getContentPane (add text-area))
>>>>        (.setMinimumSize f (java.awt.Dimension. 200 200))
>>>>        (.setVisible f true)
>>>>        f))
>>>>
>>>> (def text-area-writer
>>>>      (proxy [java.io.Writer] []
>>>>        (close [])
>>>>        (flush [])
>>>>        (write [^chars chrs ^int offs ^int len]
>>>>          (.append text-area (String. chrs offs len)))))
>>>>
>>>> When I load the code above I get an "IllegalArgumentException: Unable
>>>> to resolve classname: int" so I think I'm not type hinting correctly.
>>>
>>> Indeed. You can't (in 1.2 at least) type hint "int" though you can
>>> "ints" (array of int). Note that int is a primitive type while array
>>> of int is a reference type.
>>>
>>> Type hinting as Integer shouldn't throw exceptions, but you can
>>> probably omit all but the chars hint and have the correct String
>>> constructor overload selected.
>>
>> I tried with 1.3.0-alpha5. With type hints I get "CompilerException
>> java.lang.IllegalArgumentException: Only long and double primitives
>> are supported". If I only keep the ^chars hint I get an ArityException
>> when I do (.write text-area-writer "hello").
>
> Does it work with 1.2? Where exactly is the ArityException being
> thrown -- for what function or method?

It didn't work in 1.2 either. Here is some more info on the exception
thrown (this is with 1.3.0-alpha5)

user=> (.write text-area-writer "Hello, World!")
ArityException Wrong number of args (2) passed to: user$fn--38$fn
clojure.lang.AFn.throwArity (AFn.java\
:439)
user=> (pst)
ArityException Wrong number of args (2) passed to: user$fn--38$fn
        user.proxy$java.io.Writer$0.write (:-1)
        sun.reflect.NativeMethodAccessorImpl.invoke0
(NativeMethodAccessorImpl.java:-2)
        sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:57)
        sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:43)
        java.lang.reflect.Method.invoke (Method.java:616)
        clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:90)
        clojure.lang.Reflector.invokeInstanceMethod (Reflector.java:28)
        user/eval47 (NO_SOURCE_FILE:4)
        clojure.lang.Compiler.eval (Compiler.java:6223)
        clojure.lang.Compiler.eval (Compiler.java:6190)
        clojure.core/eval (core.clj:2680)
        clojure.main/repl/read-eval-print--5617 (main.clj:180)
nil
user=>

Thanks for helping out with this Ken!

>
> --
> 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

Reply via email to