No default source file encoding in place

10 views
Skip to first unread message

Chas Emerick

unread,
Jul 30, 2008, 9:39:52 AM7/30/08
to Clojure
Currently, Clojure doesn't have a default source file encoding; said
another way, when loading a file (either via load-file or
RT.loadResourceScript, and therefore also when using lib's use or
require forms), Clojure doesn't specify an encoding to use. In the
absence of a specified encoding, java.io.InputStreamReader will
default to the current system encoding (the name of which is set in
the file.encoding Java system property) -- on my system, this is
"MacRoman".

Given this, any strings that contain non-ascii unicode characters are
generally read incorrectly (and in varying ways on different
systems). Either Clojure needs to watch for a per-file encoding
indicator in a special comment at the top of each file (ick!), or it
should just use a reasonable default. I would absolutely suggest and
prefer the latter, with UTF-8 as the default (UTF-8 being widely
supported, very functional, and the closest to a semi-standard file
encoding, at least in the programming circles I travel in).

Attached is a patch that makes the necessary changes that result in
UTF-8 being used as the encoding for all Clojure file loading; this
portion is (I think) exactly right. The patch also applies UTF-8
encoding to all repl input and output, which I'm slightly less sure
of -- it works nicely on my system (OS X w/ JDK 1.5), but there may
be details about how encodings are applied to console input and
output that I'm not accounting for here. Comments welcome.

Cheers,

- Chas

default_encoding.patch

Stuart Sierra

unread,
Jul 30, 2008, 10:20:17 AM7/30/08
to Clojure
+1 for UTF-8.

user=> (def π Math/PI)
#'user/π
user=> π
3.141592653589793

But my Emacs font can't render that. :(
-Stuart
>  default_encoding.patch
> 2KDownload

Chas Emerick

unread,
Jul 30, 2008, 4:02:14 PM7/30/08
to clo...@googlegroups.com

On Jul 30, 2008, at 10:20 AM, Stuart Sierra wrote:

>
> +1 for UTF-8.
>
> user=> (def π Math/PI)
> #'user/π
> user=> π
> 3.141592653589793
>
> But my Emacs font can't render that. :(
> -Stuart

/me relaxes in the comfortable embrace of enclojure / NetBeans. ;-)

- Chas

Reply all
Reply to author
Forward
0 new messages