when I first used :-encoding(utf8). I got a compile error, complaining about the use of greek letters in the predicate. using :-encoding(utf16be). I got rid of the error, but now there seems to be something wrong with the file format (unexpected EOF). Line 3 is the :-encoding(utf16be). obviously this line is not 945 chars long.
Ok. I found out that using greek letters is not the issue. I can use the greek letter THETA for a variable and assign a value, and I can do calculations with it. So the problem is in the file format.
I guess the first letter of a Prolog logical variable in a Prolog
text must have the code_type/2 property prolog_var_start.
Since the Greek Alphabeth has lower case and upper case,
not all letters lead to Prolog logical Variables. You
can use the SWI-Prolog interactive top-level to play
around with the code_type/2 property:
?- code_type('Δ', X), atom(X), sub_atom(X, 0, _, _, 'prolog_').
X = prolog_var_start ;
X = prolog_identifier_continue ;
false.
?- code_type('δ', X), atom(X), sub_atom(X, 0, _, _, 'prolog_').
X = prolog_atom_start ;
X = prolog_identifier_continue ;
false.
But you figured that out already so the bug is possibly somewhere else?
Maybe utf16be is a little unmaintained, and needs some
revised testing? Even the test cases by Ulrich Neumerkel
don’t make any sense at all:
File test_pio.pl:
max_char(utf16be, Max) :-
( current_prolog_flag(windows, true)
-> Max = 0xffff % UCS-2
; Max = 0xfffff % Full Unicode range
).
I think the SWI-Prolog windows limitation has been lifted, right?
And to the best of my knowledge Unicode range has max = 0x10FFFF and not max = 0xFFFFF.
On Windows SWI-Prolog gives me:
?- X = 0x10FFFF.
X = 1114111.
?- current_prolog_flag(max_char_code, X).
X = 1114111.
If all else fails, you could try saving your Prolog text in the encoding
format utf8 instead of the encoding format utf16be.
Oh my word! it works
I changed to encoding(utf8) instead of encoding(utf16be).
It didn’t work the first time though, and apparently the following in line 1 is also necessary: /* -*- coding UTF-16 -*- */
it looks a bit wonky but the outer /* … */ were necessary to protect from compile errors from SWI-Prolog.
So now I have:
Right. Yes, this is all outdated. I don’t think there is anything wrong with UTF-16 encoding, but it reads the encoding directive in the initial encoding. The initial encoding is determined by the BOM marker or, if this is not present, by the current locale.
just an afterthought, variables still have to be Capitalized. So small cap rho for density is a no-no, but Capital Rho is ok. So I’ll say it works almost as intented.