ERROR: /Applications/SWI-Prolog.app/Contents/swipl/library/win_menu.pl:196: ...................

194 views
Skip to first unread message

Nitsa Kara

unread,
Dec 11, 2015, 6:48:21 PM12/11/15
to SWI-Prolog
Hi, I have MacBook pro and I am using SWI prolog. When the program starts, it appears an error: 

ERROR: /Applications/SWI-Prolog.app/Contents/swipl/library/win_menu.pl:196: Initialization goal raised exception:

ERROR: file_base_name/2: Cannot represent due to `encoding' (Cannot represent char U0395 using current locale encoding).


When I am trying to consult a file, the program crashes. I have tried everything and I don't know what else can I do. If there is someone who can help me with this.

Thanx

Jan Wielemaker

unread,
Dec 12, 2015, 3:51:46 AM12/12/15
to Nitsa Kara, SWI-Prolog
This is an open issue. The Mac doesn't pass the language to applications
in the normal way (by setting the LANG environment) and SWI-Prolog doesn't
(yet) use the MacOS framework calls to get the language configured the
Mac way. There are some options:

- Someone helps fixing that stuff ... Carlo, could Qt initialise
the locale for us?
- Get LANG environment passed. I think the terminal initialises this
properly, so you can get the proper value from there. Not sure
though. Search for "MacOS plist environment".
- Use ~/.swiplrc and call setlocale/3 as in

:- initialization setlocale(all, _, SomeLocale).

You find the available locales using `locale -a` in a terminal.

Not sure whether or not the last one is in time. I think the Mac uses
UTF-8 for non-ASCII. In that case, the following in ~/.swiplrc might work
too:

:- initialization set_prolog_flag(encoding, utf8).
:- set_stream(user_input, encoding(utf8)).
:- set_stream(user_output, encoding(utf8)).
:- set_stream(user_error, encoding(utf8)).

Cheers --- Jan


>
> Thanx
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

Kuniaki Mukai

unread,
Dec 12, 2015, 5:27:55 AM12/12/15
to Jan Wielemaker, Nitsa Kara, SWI-Prolog
I am a mac user and had a similar problem. I am not sure what
the problem really is, but ...

I put into the user startup item folder an application
which executes the following two lines shell script

#! /bin/sh
/bin/launchctl setenv LANG ja_JP.UTF-8

"ja_JP.UTF-8” must be replaced with an appropriate one for others.
There are several easy ways to convert a shell script to a mac appication, but
I don't remember how I did it (Automator ?) for now. Any way it must be
a standard mac way .

Kuniaki Mukai
> To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
> Visit this group at https://groups.google.com/group/swi-prolog.

Carlo Capelli

unread,
Dec 12, 2015, 8:35:24 AM12/12/15
to Jan Wielemaker, Nitsa Kara, SWI-Prolog
2015-12-12 9:51 GMT+01:00 Jan Wielemaker <J.Wiel...@vu.nl>:
On 12/12/2015 12:48 AM, Nitsa Kara wrote:
> Hi, I have MacBook pro and I am using SWI prolog. When the program
> starts, it appears an error:
>
> ERROR:
> /Applications/SWI-Prolog.app/Contents/swipl/library/win_menu.pl:196:
> Initialization goal raised exception:
>
> ERROR: file_base_name/2: Cannot represent due to `encoding' (Cannot
> represent char U0395 using current locale encoding).
>
>
> When I am trying to consult a file, the program crashes. I have tried
> everything and I don't know what else can I do. If there is someone who
> can help me with this.

This is an open issue.  The Mac doesn't pass the language to applications
in the normal way (by setting the LANG environment) and SWI-Prolog doesn't
(yet) use the MacOS framework calls to get the language configured the
Mac way.  There are some options:

  - Someone helps fixing that stuff ...  Carlo, could Qt initialise
    the locale for us?

I think it does... QApplication should call setlocale(LC_ALL,"")
At least, a tiny library I'm using (xdot, a graphviz component) was failing as a consequence of my locale decimal separator being ',' instead of the expected '.'

Alas, I'm of little help, I cannot test a MacOS right now.

To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.

Jan Wielemaker

unread,
Dec 12, 2015, 9:04:16 AM12/12/15
to Carlo Capelli, Nitsa Kara, SWI-Prolog
On 12/12/2015 02:35 PM, Carlo Capelli wrote:

> - Someone helps fixing that stuff ... Carlo, could Qt initialise
> the locale for us?
>
>
> I think it does... QApplication should call setlocale(LC_ALL,"")
> At least, a tiny library I'm using (xdot, a graphviz component) was
> failing as a consequence of my locale decimal separator being ','
> instead of the expected '.'
>
> Alas, I'm of little help, I cannot test a MacOS right now.

Yeah. `setlocale(LC_ALL,"")` is what you can do on a normal Unix
system, which provides the default locale in the LANG environment.
Alas, MacOSX doesn't do that for applications :( As Kuniaki pointed
out, you can set LANG for applications using /bin/launchctl (didn't
know that), but that is not the Mac way. I guess if you use their
platform stuff you get all that for free, but if you work from a
cross-platform code base you need to figure out how to do it. I once
found some pointers. Looked scary and complicated ... and I can't
find the link back :(

Cheers --- Jan
Reply all
Reply to author
Forward
0 new messages