Question

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 ?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top