SWI Prolog in Mac OS X

2,353 views
Skip to first unread message

to...@hoof.demon.co.uk

unread,
Sep 30, 2015, 9:34:45 AM9/30/15
to SWI-Prolog
I've successfully downloaded SWI-Prolog  on to my Mac, having used it successfully under Windows for many years.  I'm running Yosemite, and have dragged it to the 'Applications' folder.

My problem is that I can't get a simple text file to load by putting it in the same folder as SWIProlog and typing consult(test) at the Prolog prompt.

 I get this error message when I try to run it:

Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.2.3)

Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam

SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to redistribute it under certain conditions.

Please visit http://www.swi-prolog.org for details.


For help, use ?- help(Topic). or ?- apropos(Word).


1 ?- consult(test).

ERROR: source_sink `test' does not exist

2 ?-


I have virtually zero Unix capability, so answers predicated on the assumption that I can solve the problem at terminal level won't really help.

My thanks to anyone who can suggest a way round the problem.

Tony DRAPKIN

Paulo Moura

unread,
Sep 30, 2015, 9:41:30 AM9/30/15
to SWI-Prolog
Try to use the pwd/0, cd/0, cd/1 predicates to check the current working directory and to navigate to where your Prolog file resides.
> --
> 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.
> Visit this group at http://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

-----------------------------------------------------------------
Paulo Moura
Logtalk developer

Email: <mailto:pmo...@logtalk.org>
Web: <http://logtalk.org/>
-----------------------------------------------------------------




to...@hoof.demon.co.uk

unread,
Oct 1, 2015, 5:16:39 PM10/1/15
to SWI-Prolog
I have tried your suggestions, but to no avail. I have got SWI-Prolog installed in the 'Applications' folder and a test file in the same folder, but I don't really think I know what I'm doing.

In desperation, I dragged the test file into the Prolog window and got:



For help, use ?- help(Topic). or ?- apropos(Word).


1 ?- file:///Applications/test.txt


An explanation on how to proceed on the level of 'SWI-Prolog for Dummies' would be helpful.

to...@hoof.demon.co.uk

unread,
Oct 1, 2015, 5:29:24 PM10/1/15
to SWI-Prolog
Eureka!  After a certain amount of fiddling about I got a result.


For help, use ?- help(Topic). or ?- apropos(Word).


1 ?- file:///Applications/test.txt.

ERROR: Syntax error: Operator expected

ERROR: fil

ERROR: ** here **

ERROR: e:///Applications/test.txt .

1 ?- ['Applications/test.txt'].

true.


2 ?- loves(X, Y).

X = tony,

Y = jennifer.


3 ?-


If this is correct, I think I may be ok from now on.


Thanks.

Paulo Moura

unread,
Oct 1, 2015, 5:37:38 PM10/1/15
to SWI-Prolog

> On 01/10/2015, at 22:16, to...@hoof.demon.co.uk wrote:
>
> I have tried your suggestions, but to no avail. I have got SWI-Prolog installed in the 'Applications' folder and a test file in the same folder, but I don't really think I know what I'm doing.
>
> In desperation, I dragged the test file into the Prolog window and got:
>
>
> For help, use ?- help(Topic). or ?- apropos(Word).
>
> 1 ?- file:///Applications/test.txt
>
> An explanation on how to proceed on the level of 'SWI-Prolog for Dummies' would be helpful.

After opening the SWi-Prolog.app application, type:

1 ?- pwd.
% /
true.

This tells you that the current working directory is the root of the file system. Use the cd/1 predicate to change this directory to where your Prolog file resides. For example, if you Prolog file is in your home directory, type:

2 ?- cd.
true

You can then load the file by typing:

3 ?- ['test.pl'].

or simply

3 ?- [test].

An alternative is to use the full path to the file. E.g.

3 ?- ['/Users/tony/test.pl'].

Hope this helps. Cheers,

Paulo

Jan Wielemaker

unread,
Oct 2, 2015, 3:55:18 AM10/2/15
to Paulo Moura, SWI-Prolog
Note there is a menu, which gives File/Consult ... I only see that it
doesn't give feedback anymore because the default loading is now silent.
Will change that.

From the Finder, Open with should also give the option to open a .pl
file using SWI-Prolog.

A better out-of-the-box experience on the Mac would be useful. Known
issues:

- The app doesn't pick up locale. Somehow that is not passed through
the environment for apps. I never managed to find out how to
properly initialise the locale for the app.
- We need some way to register the commandline tools in $PATH. How?
Add a menu entry in Settings that will edit the users shell init
file?

Anything else?

Cheers --- Jan

Carlo Capelli

unread,
Oct 2, 2015, 6:24:27 AM10/2/15
to Jan Wielemaker, Paulo Moura, SWI-Prolog
Hi Jan, Paulo

today I had my first experience as user of swipl-win :-)
I'm not a MacOS user, but I have temporarily a Mavericks machine available.
The installation it's so simple, really pleasant...

On Ubuntu, after I've (re)built from source, I open (with QtCreator) ~/swipl-dev/packages/swipl-win/swipl-win.pro and build ...
I guess I'm the only one in the world to run Qt based swipl-win on Linux :-)
I use swipl-win occasionally, since I test my loqt project...

I have some small extension to UI, this one I find useful:
highlighting matched symbols (by text selection) in console helps to make sense of the trace/0 output.
I could easily add to swipl-win, forking from github.

About locale, I did found that Graphviz libraries (like xdot.so) require setting

    // xdot required
    setlocale(LC_ALL, "C");

due to Qt changing locale (as expected) in QApplication constructor, and before calling any code from xdot.so
Could this be the problem ? That is, some unexpected change to locale performed by some library ?

Interaction among platforms turns out to be complicated...
Right now, I'm facing that Qt inhibits GObject usage, so it rules out the awesome PLGI by Keri...

Carlo

Jan Wielemaker

unread,
Oct 2, 2015, 8:11:15 AM10/2/15
to Carlo Capelli, Paulo Moura, SWI-Prolog
On 10/02/2015 12:24 PM, Carlo Capelli wrote:
> Hi Jan, Paulo
>
> today I had my first experience as user of swipl-win :-) I'm not a
> MacOS user, but I have temporarily a Mavericks machine available. The
> installation it's so simple, really pleasant...

True :) Only building it is a bit of a flaky process. Quite frequently
needs patches as new Xcode releases appear :(

> On Ubuntu, after I've (re)built from source, I open (with QtCreator)
> ~/swipl-dev/packages/swipl-win/swipl-win.pro <http://swipl-win.pro>
> and build ... I guess I'm the only one in the world to run Qt based
> swipl-win on Linux :-) I use swipl-win occasionally, since I test my
> loqt project...

Probably :)

> I have some small extension to UI, this one I find useful:
> highlighting matched symbols (by text selection) in console helps to
> make sense of the trace/0 output. I could easily add to swipl-win,
> forking from github.

If you send a pull request, I'm happy to apply it.

> About locale, I did found that Graphviz libraries (like xdot.so)
> require setting
>
> // xdot required setlocale(LC_ALL, "C");

That is the opposite. SWI-Prolog is Unicode aware and wants to
play with the locale. Normally that is passed through $LANG, but
if you start a Mac app, the environment is ignored. I don't know
how one is supposed to get the user desired locale :(

> due to Qt changing locale (as expected) in QApplication constructor,
> and before calling any code from xdot.so Could this be the problem ?
> That is, some unexpected change to locale performed by some library

It doesn't seem to do that. Prolog should be happy if it is embedded
in an application that sets the locale, but it isn't :( Might under
Linux as passing the locale works different there.

> Interaction among platforms turns out to be complicated... Right now,
> I'm facing that Qt inhibits GObject usage, so it rules out the
> awesome PLGI by Keri...

Not surprised. Having one process talking to X11 from multiple
libraries asks for some synchronization.

Cheers --- Jan

Samer Abdallah

unread,
Oct 2, 2015, 8:19:23 AM10/2/15
to Jan Wielemaker, Carlo Capelli, Paulo Moura, <swi-prolog@googlegroups.com>

On 2 Oct 2015, at 13:11, Jan Wielemaker <J.Wiel...@vu.nl> wrote:

> On 10/02/2015 12:24 PM, Carlo Capelli wrote:
>> Hi Jan, Paulo
>>
>> today I had my first experience as user of swipl-win :-) I'm not a
>> MacOS user, but I have temporarily a Mavericks machine available. The
>> installation it's so simple, really pleasant...
>

Ditto.

> That is the opposite. SWI-Prolog is Unicode aware and wants to
> play with the locale. Normally that is passed through $LANG, but
> if you start a Mac app, the environment is ignored. I don't know
> how one is supposed to get the user desired locale :(

Funny - I just hit exactly that problem now try to use the Matlab interface
library from inside swill-win.app. When I launch with open swipl-win.app
from the command line, it’s fine, but if I launch from the GUI, no LANG,
a probably lots of other missing environment that stops it working..

Samer.

ps. damn spelling autocorrector keeps replacing swill-win.app with swill-win.app

signature.asc

Jan Wielemaker

unread,
Oct 2, 2015, 8:24:14 AM10/2/15
to Samer Abdallah, Carlo Capelli, Paulo Moura, <swi-prolog@googlegroups.com>
You can probably use setlocale/3 and setenv/2 from ~/.swiplrc to get it
still working. That fails if you need to extend the .dylib search
path using the environment as both MacOS and Linux read this on program
startup and subsequent changes have no effect.

Cheers --- Jan

>
> Samer.
>
> ps. damn spelling autocorrector keeps replacing swill-win.app with swill-win.app
>

Paulo Moura

unread,
Oct 2, 2015, 8:51:00 AM10/2/15
to <swi-prolog@googlegroups.com>
Mac OS X GUI applications don't run on top of the BSD layer but parallel to it. I.e. they are not shell processes like e.g. on Linux. Thus, they don't inherit any environment variables set for command-line shells.

Cheers,

Paulo

Samer Abdallah

unread,
Oct 2, 2015, 8:57:36 AM10/2/15
to Paulo Moura, <swi-prolog@googlegroups.com>

On 2 Oct 2015, at 13:50, Paulo Moura <pjlm...@gmail.com> wrote:

>
>> On 02/10/2015, at 13:19, Samer Abdallah <seventy...@gmail.com> wrote:
>>
>>
>> On 2 Oct 2015, at 13:11, Jan Wielemaker <J.Wiel...@vu.nl> wrote:
>>
>>> On 10/02/2015 12:24 PM, Carlo Capelli wrote:
>>>> Hi Jan, Paulo
>>>>
>>>> today I had my first experience as user of swipl-win :-) I'm not a
>>>> MacOS user, but I have temporarily a Mavericks machine available. The
>>>> installation it's so simple, really pleasant...
>>>
>>
>> Ditto.
>>
>>> That is the opposite. SWI-Prolog is Unicode aware and wants to
>>> play with the locale. Normally that is passed through $LANG, but
>>> if you start a Mac app, the environment is ignored. I don't know
>>> how one is supposed to get the user desired locale :(
>>
>> Funny - I just hit exactly that problem now try to use the Matlab interface
>> library from inside swill-win.app. When I launch with open swipl-win.app
>> from the command line, it’s fine, but if I launch from the GUI, no LANG,
>> a probably lots of other missing environment that stops it working..
>
> Mac OS X GUI applications don't run on top of the BSD layer but parallel to it. I.e. they are not shell processes like e.g. on Linux. Thus, they don't inherit any environment variables set for command-line shells.

Yes, I know - there’s a special property list file you can create somewhere to
define the environment for graphical applications … <pause while googling> …
it’s ~/.MacOSX/environment.plist.
Except that apparently this doesn’t work any more - see here for more info:
http://stackoverflow.com/questions/603785/environment-variables-in-mac-os-x

cheers,
Samer

>
> Cheers,
>
> Paulo
>
>
> -----------------------------------------------------------------
> Paulo Moura
> Logtalk developer
>
> Email: <mailto:pmo...@logtalk.org>
> Web: <http://logtalk.org/>
> -----------------------------------------------------------------
>
>
>
>
signature.asc

Paulo Moura

unread,
Oct 2, 2015, 9:09:32 AM10/2/15
to <swi-prolog@googlegroups.com>

> On 02/10/2015, at 13:57, Samer Abdallah <seventy...@gmail.com> wrote:
>
>
> On 2 Oct 2015, at 13:50, Paulo Moura <pjlm...@gmail.com> wrote:
>
>>
>>> On 02/10/2015, at 13:19, Samer Abdallah <seventy...@gmail.com> wrote:
>>>
>>>
>>> On 2 Oct 2015, at 13:11, Jan Wielemaker <J.Wiel...@vu.nl> wrote:
>>>
>>>> On 10/02/2015 12:24 PM, Carlo Capelli wrote:
>>>>> Hi Jan, Paulo
>>>>>
>>>>> today I had my first experience as user of swipl-win :-) I'm not a
>>>>> MacOS user, but I have temporarily a Mavericks machine available. The
>>>>> installation it's so simple, really pleasant...
>>>>
>>>
>>> Ditto.
>>>
>>>> That is the opposite. SWI-Prolog is Unicode aware and wants to
>>>> play with the locale. Normally that is passed through $LANG, but
>>>> if you start a Mac app, the environment is ignored. I don't know
>>>> how one is supposed to get the user desired locale :(
>>>
>>> Funny - I just hit exactly that problem now try to use the Matlab interface
>>> library from inside swill-win.app. When I launch with open swipl-win.app
>>> from the command line, it’s fine, but if I launch from the GUI, no LANG,
>>> a probably lots of other missing environment that stops it working..
>>
>> Mac OS X GUI applications don't run on top of the BSD layer but parallel to it. I.e. they are not shell processes like e.g. on Linux. Thus, they don't inherit any environment variables set for command-line shells.
>
> Yes, I know - there’s a special property list file you can create somewhere to
> define the environment for graphical applications … <pause while googling> …
> it’s ~/.MacOSX/environment.plist.
> Except that apparently this doesn’t work any more - see here for more info:
> http://stackoverflow.com/questions/603785/environment-variables-in-mac-os-x

The solution I use for automatically load Logtalk (which expects two environment variables to be defined) when starting the SWI-Prolog.app GUI application is to define in the ~/.swiplrc file:

:- setenv('LOGTALKHOME', '/opt/local/share/logtalk').
:- setenv('LOGTALKUSER', '/Users/pmoura/logtalk').

Just an workaround and not a solution, I know, as it implies duplication of the definitions of the variables and thus doesn't inherit changes :(

Paulo Moura

unread,
Oct 2, 2015, 9:16:33 AM10/2/15
to SWI-Prolog

> On 02/10/2015, at 08:55, Jan Wielemaker <J.Wiel...@vu.nl> wrote:
>
> Note there is a menu, which gives File/Consult ... I only see that it
> doesn't give feedback anymore because the default loading is now silent.
> Will change that.
>
> From the Finder, Open with should also give the option to open a .pl
> file using SWI-Prolog.
>
> A better out-of-the-box experience on the Mac would be useful. Known issues:
>
> - The app doesn't pick up locale. Somehow that is not passed through
> the environment for apps. I never managed to find out how to
> properly initialise the locale for the app.
> - We need some way to register the commandline tools in $PATH. How?
> Add a menu entry in Settings that will edit the users shell init
> file?

That's the typical solution. Have a preference setting span a shell process calling a script included in the .app bundle that does that for you. I do something similar in Logtalk's Mac OS X installer. This installer supports a postflight script, which I use to set Logtalk's environment variables:

https://github.com/LogtalkDotOrg/logtalk3/blob/master/scripts/macosx/postflight

May you can adapt it to register the commandline tools in $PATH for all users?

Cheers,

Paulo

to...@hoof.demon.co.uk

unread,
Oct 2, 2015, 4:42:48 PM10/2/15
to SWI-Prolog
Thanks for the suggestions so far.

However, I now have two further problems.

On compiling a more complicated program than the simple test program I used initially, I get this message:

1 ?- ['Applications/nr2014.txt'].

ERROR: /Applications/nr2014.txt:89:1: Syntax error: Unexpected end of clause

true.


There can't be a syntax error because the program compiles perfectly well in the Windows XP version of SWI-Prolog. In any event, what do the numbers 89:1 refer to?



2 ?- go.

ERROR: open/3: No permission to open source_sink `nr_hfdata' (Permission denied)

3 ?-

The program tries to open a file called 'nr_hfdata' and write to it. This works perfectly well in the XP version, but it looks as if the I/O calls in Mac OS X work very differently.


The code that causes this error message looks like this:


calc_odds(_, [], []):-
open(nr_hfdata, append, Out),
set_output(Out),
nl,
close(Out),
open(spread_data, append, Spread_output),
set_output(Spread_output),
nl,
close(Spread_output).


Any ideas anyone?


Thanks,


Tony




Reply all
Reply to author
Forward
0 new messages