[scala] A character encoding problem when using scala interactive interpreter

View: New views
5 Messages — Rating Filter:   Alert me  

[scala] A character encoding problem when using scala interactive interpreter

by Kota Mizushima :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello.

I wrote the following code and saved it as 'hello.scala' in UTF-8.

object こんにちは {// "こんにちは" means "hello" in English.
  def main(args: Array[String]) {
    println("hello, world")
  }
}

This file is successfully compiled by scalac(scala2.7.1.final on
Windows XP Service Pack 2).
> scalac hello.scala

But it is failed to load this file by ":load" command in scala
interactive interpreter(on cmd.exe).
> scala
Welcome to Scala version 2.7.1.final (Java HotSpot(TM) Client VM, Java 1.6.0).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :load hello.scala
Loading hello.scala...
<console>:1: error: illegal character: '。'
       object 縺薙s縺ォ縺。縺ッ {
                    ^
main: (Array[String])Unit

It is successful to load this file if I save it in Windows-31J.  It seems that
":load" command processes a file in the platform default encoding.  I think
that ":load" command should process a file in the same encoding as specified
by -encoding option(or UTF-8 if the encoding is not specified).

Re: [scala] A character encoding problem when using scala interactive interpreter

by Arrgh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 6-Jun-08, at 11:23 PM, Kota Mizushima wrote:
> I think that ":load" command should process a file in the same  
> encoding as specified
> by -encoding option(or UTF-8 if the encoding is not specified).

Have you tried -Dfile.encoding=UTF8?  IIRC it overrides the platform  
default encoding.

-0xe1a


Re: [scala] A character encoding problem when using scala interactive interpreter

by Kota Mizushima :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Have you tried -Dfile.encoding=UTF8?  IIRC it overrides the platform default
> encoding.
>
> -0xe1a

Thanks. I tried -Dfile.encoding=UTF8, but the same problem happened.
While I searched the reason, I found following page.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4163515

Quoting from that page, 'The "file.encoding" property is not required
by the J2SE platform specification; it's an internal detail of Sun's
implementations and should not be examined or modified by user code.'

Re: [scala] A character encoding problem when using scala interactive interpreter

by David MacIver :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, Jun 8, 2008 at 1:19 AM, Kota Mizushima <mizukota@...> wrote:

>> Have you tried -Dfile.encoding=UTF8?  IIRC it overrides the platform default
>> encoding.
>>
>> -0xe1a
>
> Thanks. I tried -Dfile.encoding=UTF8, but the same problem happened.
> While I searched the reason, I found following page.
>
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4163515
>
> Quoting from that page, 'The "file.encoding" property is not required
> by the J2SE platform specification; it's an internal detail of Sun's
> implementations and should not be examined or modified by user code.'
>

This is a known bug in the interpreter. See
http://lampsvn.epfl.ch/trac/scala/ticket/992

Re: [scala] A character encoding problem when using scala interactive interpreter

by Kota Mizushima :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2008/6/8 David MacIver <david.maciver@...>:

> On Sun, Jun 8, 2008 at 1:19 AM, Kota Mizushima <mizukota@...> wrote:
>>> Have you tried -Dfile.encoding=UTF8?  IIRC it overrides the platform default
>>> encoding.
>>>
>>> -0xe1a
>>
>> Thanks. I tried -Dfile.encoding=UTF8, but the same problem happened.
>> While I searched the reason, I found following page.
>>
>> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4163515
>>
>> Quoting from that page, 'The "file.encoding" property is not required
>> by the J2SE platform specification; it's an internal detail of Sun's
>> implementations and should not be examined or modified by user code.'
>>
>
> This is a known bug in the interpreter. See
> http://lampsvn.epfl.ch/trac/scala/ticket/992

Thanks for the pointer to the trac ticket that I didn't know.
However, I think that ":load" command should load files not in the
platform default encoding but in the encoding specified by
-encoding(or UTF-8 if not specified) to be consistent with scalac in
the first place.

--
Kota Mizushima
e-mail: mizukota@...
LightInTheBox - Buy quality products at wholesale price!