views:

73

answers:

1

Hey, I am trying to implement a function to differentiate between french vowels and consonnants. It should be trivial, let's see what I wrote down :

-define(vowels,"aeiouyàâéèêëôù").

is_vowel(Char) -> C = string:to_lower(Char),
                  lists:member(C,?vowels).

It's pretty simple, but it behaves incorrectly :

2> char:is_vowel($â).
false

While the interpreted version works well :

3> C = string:to_lower($â), lists:member(C,"aeiouyàâéèêëôù").
true

What's going on ?

+2  A: 

The most likely thing here is a conflict of encodings. Your vowels list in the compiled code is using different character values for the accented characters. You should be able to see this by defining acirc() -> $â. in your compiled code and looking at the number output by calling char:acirc(). versus $â. in the interpreter. I think that the compiler assumes that source files are in ISO-Latin-1 encoding, but the interpreter will consult your locale settings and use that encoding, probably UTF-8 if you're on a modern linux distro. See Using Unicode in Erlang for more information.

Geoff Reedy
Seems you are right ; indeed I get an encoding error when implementing acirc(). I've to write something like : acirc() -> lists:nth(1,"â").Which corresponds to à in the interpreter. I'll read the document you made mention of. Thanks.
erevfall