Primitive char Type

2009-06-13 Thread tmountain

I'm writing some simple code, and I believe I'm running into trouble
getting a primitive char.

user=> (def s (new StringBuilder "aaa"))
#'user/s

; Java method signature is setCharAt(int index, char ch)
user=> (. s setCharAt (int 0) (char \a))

java.lang.IllegalArgumentException: No matching method found:
setCharAt for class java.lang.StringBuilder (NO_SOURCE_FILE:0)
user=> (type (char \a))
java.lang.Character
; should be char?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Primitive char Type

2009-06-13 Thread Kevin Downey

user=> (def s (StringBuilder. "aaa"))
#'user/s
user=> (. s setCharAt 0 \b)
nil
user=> s
#
user=> (. s setCharAt (int 0) (char \b))
nil
user=> (. s setCharAt (int 0) (char \e))
nil
user=> s
#
user=>

works for me


On Sat, Jun 13, 2009 at 7:28 PM, tmountain wrote:
>
> I'm writing some simple code, and I believe I'm running into trouble
> getting a primitive char.
>
> user=> (def s (new StringBuilder "aaa"))
> #'user/s
>
> ; Java method signature is setCharAt(int index, char ch)
> user=> (. s setCharAt (int 0) (char \a))
>
> java.lang.IllegalArgumentException: No matching method found:
> setCharAt for class java.lang.StringBuilder (NO_SOURCE_FILE:0)
> user=> (type (char \a))
> java.lang.Character
> ; should be char?
> >
>



-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

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



Re: Primitive char Type

2009-06-13 Thread Stephen C. Gilardi


On Jun 13, 2009, at 7:37 PM, Kevin Downey wrote:


works for me


It's working for me in Java 6, but not Java 5. It looks like something  
changed there. In Java 5, I'm getting:


user=> (.setCharAt s 0 \c)
java.lang.IllegalArgumentException: Can't call public method of non- 
public class: public void  
java.lang.AbstractStringBuilder.setCharAt(int,char) (NO_SOURCE_FILE:0)


I'm not sure why.

--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: Primitive char Type

2009-06-13 Thread Wrexsoul

On Jun 13, 10:46 pm, "Stephen C. Gilardi"  wrote:
> On Jun 13, 2009, at 7:37 PM, Kevin Downey wrote:
>
> > works for me
>
> It's working for me in Java 6, but not Java 5. It looks like something  
> changed there.

Autoboxing.

What I miss is foo-array for foo not in #{int long float double},
particularly for (= foo byte). I'm resorting to Java for the lowest-
level I/O code for binary files, which is a pain because to reload
changes to a Java class at the REPL means restarting the REPL, which
in turn means losing any testing-purposes defs, defns, and the like
I'd entered there, as well as the history.

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



Re: Primitive char Type

2009-06-14 Thread James Reeves

On Jun 14, 4:40 am, Wrexsoul  wrote:
> What I miss is foo-array for foo not in #{int long float double},
> particularly for (= foo byte).

You can use (make-array Byte/TYPE size) and (into-array Byte/TYPE byte-
coll).

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



Re: Primitive char Type

2009-06-14 Thread James Reeves

On Jun 14, 3:28 am, tmountain  wrote:
> java.lang.IllegalArgumentException: No matching method found:
> setCharAt for class java.lang.StringBuilder (NO_SOURCE_FILE:0)
> user=> (type (char \a))
> java.lang.Character
> ; should be char?

You could try: (.charValue \a)

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



Re: Primitive char Type

2009-06-14 Thread tmountain

That doesn't work either. It appears this isn't an issue with Java 6,
but that doesn't help me on my PPC powerbook, which is apparently
stuck with the Java 5 JRE for the foreseeable future.

Thanks,
Travis

On Jun 14, 10:44 am, James Reeves  wrote:
> On Jun 14, 3:28 am, tmountain  wrote:
>
> > java.lang.IllegalArgumentException: No matching method found:
> > setCharAt for class java.lang.StringBuilder (NO_SOURCE_FILE:0)
> > user=> (type (char \a))
> > java.lang.Character
> > ; should be char?
>
> You could try: (.charValue \a)
>
> - James
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Primitive char Type

2009-06-14 Thread Stephen C. Gilardi


On Jun 13, 2009, at 10:46 PM, Stephen C. Gilardi wrote:


user=> (.setCharAt s 0 \c)
java.lang.IllegalArgumentException: Can't call public method of non- 
public class: public void  
java.lang.AbstractStringBuilder.setCharAt(int,char) (NO_SOURCE_FILE:0)


I'm not sure why.


StringBuilder extends AbstractStringBuilder (though the JavaDoc docs  
lie and say it extends Object). AbstractStringBuilder has default  
accessibility (not public, protected, or private) which makes the  
class inaccessible to code outside the java.lang package.


In both Java SE 5 and Java SE 6, StringBuilder does not contain  
a .setCharAt method definition. It relies on the inherited public  
method in AbstractStringBuilder. (I downloaded the source code for  
both versions from Sun to check.)


In Java SE 5, when Clojure checks whether or not .setCharAt on  
StringBuilder is public, it finds that it's a public method of a non- 
public base class and throws the exception you saw. (It looks like  
you're using a version of Clojure older than 18 May 2009 (Clojure svn  
r1371). Versions later than that print the more detailed message I saw.)


In Java SE 6, Clojure's checks for accessibility of this method  
succeed and the method call works.


I'm not sure whether or not Clojure could be modified to make this  
method call work in Java 5. Google searches turn up discussion that  
this pattern of using an undocumented abstract superclass with non- 
public accessibility is not common in the JDK.


--Steve



smime.p7s
Description: S/MIME cryptographic signature


Re: Primitive char Type

2009-06-15 Thread tmountain

Wow, you really got to the bottom of this. Reading your post, it all
makes sense, but it leads me to wonder why StringBuilder was designed
in such a fashion and why the docs would go so far as to lie about it.
Either way, thanks for taking the time to help me out. This community
is a big part of what makes working with Clojure so awesome.

Travis

On Jun 14, 6:58 pm, "Stephen C. Gilardi"  wrote:
> On Jun 13, 2009, at 10:46 PM, Stephen C. Gilardi wrote:
>
> > user=> (.setCharAt s 0 \c)
> > java.lang.IllegalArgumentException: Can't call public method of non-
> > public class: public void  
> > java.lang.AbstractStringBuilder.setCharAt(int,char) (NO_SOURCE_FILE:0)
>
> > I'm not sure why.
>
> StringBuilder extends AbstractStringBuilder (though the JavaDoc docs  
> lie and say it extends Object). AbstractStringBuilder has default  
> accessibility (not public, protected, or private) which makes the  
> class inaccessible to code outside the java.lang package.
>
> In both Java SE 5 and Java SE 6, StringBuilder does not contain  
> a .setCharAt method definition. It relies on the inherited public  
> method in AbstractStringBuilder. (I downloaded the source code for  
> both versions from Sun to check.)
>
> In Java SE 5, when Clojure checks whether or not .setCharAt on  
> StringBuilder is public, it finds that it's a public method of a non-
> public base class and throws the exception you saw. (It looks like  
> you're using a version of Clojure older than 18 May 2009 (Clojure svn  
> r1371). Versions later than that print the more detailed message I saw.)
>
> In Java SE 6, Clojure's checks for accessibility of this method  
> succeed and the method call works.
>
> I'm not sure whether or not Clojure could be modified to make this  
> method call work in Java 5. Google searches turn up discussion that  
> this pattern of using an undocumented abstract superclass with non-
> public accessibility is not common in the JDK.
>
> --Steve
>
>  smime.p7s
> 3KViewDownload
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---