# How can I load a base of knowledge with SWI under iMAC?

**URL:** <https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615>\
**Category:** Help!\
**Created:** [February 17, 2021, 8:45pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615 "2021-02-17T20:45:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephanehaguenau](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@stephanehaguenau](https://swi-prolog.discourse.group/u/stephanehaguenau)\
**Post date:** [February 17, 2021, 8:45pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/1 "2021-02-17T20:45:06Z")

</div>

Hi everyone,

I am working under iMAC and I launch SWI from a terminal windows with the command open SWIProlog.app !

Once upon into SWI, how can I load a base of Knowledge?

Thanks for an advice

Stephane

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [February 17, 2021, 9:23pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/2 "2021-02-17T21:23:24Z")

</div>

> [@stephanehaguenau](#):
>
> Once upon into SWI, how can I load a base of Knowledge?

The general answer is here: [SWI-Prolog -- Loading Prolog source files](https://www.swi-prolog.org/pldoc/man?section=consulting)

The easiest way is to just execute the top-level goal  
`[path/to/my/file]` % notice that the `.pl` isn’t needed or even desirable.  
which is a short-hand for `consult(path/to/my/file)`.  
You can also use `ensure_loaded/1` and – if the knowledge base is in a module – use\_module/1 or use\_module/2. You probably don’t owant to use include/1.

---

<div class="post-metadata">

**Author:** ![stephanehaguenau](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@stephanehaguenau](https://swi-prolog.discourse.group/u/stephanehaguenau)\
**Post date:** [February 18, 2021, 8:25pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/3 "2021-02-18T20:25:28Z")

</div>

Thank you very much for you quick answer Peter.  
I apologize but I am still a stranger in the SWI-World.  
Here what I am trying to do:  
My knowledge base is in a file called template.pl.  
I launch my SWI from a terminal window with the command “open SWI.app”.  
Once upon in SWI I try to do what you have explained: “?- ensure\_loaded/1 (temp.pl).” but it doesn’t work.  
What I am doing wrong?

Thank you for your help.

Stephane

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [February 18, 2021, 9:06pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/4 "2021-02-18T21:06:29Z")

</div>

At the `:-` prompt, enter:  
`ensure_loaded(temp).`

If this fails because `temp.pl` isn’t in your current working directory, you can always give a full path, e.g. `ensure_loaded('/path/to/temp').` (The `.pl` extension is optional and generally not given.)

---

<div class="post-metadata">

**Author:** ![stephanehaguenau](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@stephanehaguenau](https://swi-prolog.discourse.group/u/stephanehaguenau)\
**Post date:** [February 18, 2021, 9:43pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/5 "2021-02-18T21:43:46Z")

</div>

My knowledge base base1.pl is in the same directory as the SWI application.  
That’s the result of my command/

?- ensure\_loaded(base1.pl).  
ERROR: Type error: `dict' expected, found `base1’ (an atom)  
ERROR: In:  
ERROR: [13] throw(error(type\_error(dict,base1),\_33146))  
ERROR: [10] ‘’(user:user: …)   
ERROR: [9]   
ERROR:  
ERROR: Note: some frames are missing due to last-call optimization.  
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [February 18, 2021, 10:54pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/6 "2021-02-18T22:54:46Z")

</div>

If you have a special character (such as “.”) in the name, you need to quote it:

```prolog
?- ensure_loaded('base1.pl').

```

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [February 19, 2021, 12:57am UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/7 "2021-02-19T00:57:24Z")

</div>

If you want to understand your error message: `base1.pl` is not a single thing – it’s three: “`base1`”, “`.`”, “`pl`”. The “`.`” has the special meaning of selecting an item from a [dict](https://www.swi-prolog.org/pldoc/man?section=bidicts). So, the error message “Type error: `dict’ expected, found `base1’ (an atom)” means that “`base`” isn’t a dict (it’s an [atom](https://www.swi-prolog.org/pldoc/man?section=glossary#gloss:atom)).

In the directive ensure\_loaded/1, the “/1” means it expects a single argument. The argument typically is an atom: you can ensure it’s an atom by quoting it with single quotes. As a convenience, ensure\_loaded/1 also allows you to have names without quotes that contain "/"s … this is actually a [compound term](https://www.swi-prolog.org/pldoc/man?section=glossary#gloss:compound) because the “`/`” is an [operator](https://www.swi-prolog.org/pldoc/man?section=glossary#gloss:operator) – unlike in regular programming languages, an operator doesn’t _do_ anything; it’s merely a bit of syntactic sugar that allows you to write `path/to/file` instead of `'/'('/'(path,to),file)` (where `path`, `to`, `file` are all atoms – they don’t need quotes because the don’t contain any special characters.

(I hope I haven’t over-explained and caused you more confusion.)

---

<div class="post-metadata">

**Author:** ![stephanehaguenau](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@stephanehaguenau](https://swi-prolog.discourse.group/u/stephanehaguenau)\
**Post date:** [February 19, 2021, 6:52pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/8 "2021-02-19T18:52:25Z")

</div>

Hello Peter,

thank you very much for your advices: I progress :-).

Now I have the following error message/  
ERROR: /Users/stephanehetzel/Desktop/Prolog/base1.pl:13:6: Syntax error: Unexpected end of file

Where can I find in the manual the part which describes how the knowledge bases shall be structured ?

Regards

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [February 19, 2021, 7:35pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/9 "2021-02-19T19:35:09Z")

</div>

I’m not sure how I could help you without getting into a full Prolog tutorial. Basically, Prolog “knowledge bases” are just Prolog programs; there’s no strong distinction.

If you post your code, we can probably help you. (I think Discourse allows attaching a file to a post)

---

<div class="post-metadata">

**Author:** ![stephanehaguenau](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@stephanehaguenau](https://swi-prolog.discourse.group/u/stephanehaguenau)\
**Post date:** [February 19, 2021, 11:02pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/10 "2021-02-19T23:02:38Z")

</div>

Hi Peter,

I can’t join my file to this message.

But here the content of the file:  
man(john) .  
woman(frida) .  
woman(nelly) .  
duck(donald) .  
loves(john,frida) .  
loves(frida,donald) .  
loves(nelly,donald) .  
loves(donald,nelly) .  
sad(X) :− loves(X,Y) , loves(Y,Z) .

Can you give me perhaps the name of a Prolog editor?

Thanks

Regards

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [February 19, 2021, 11:19pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/11 "2021-02-19T23:19:39Z")

</div>

The file looks fine, although the last line’s `:-` seems to have been modified to use a Unicode em-dash (or maybe en-dash) instead of an ordinary minus sign. The last line should be:

```prolog
sad(X) :- loves(X,Y) , loves(Y,Z) .

```

I’ve attached the corrected file.

If you load this file, you should get a warning: “Singleton variables: [Z]”.[sad.pl](https://swi-prolog.discourse.group/uploads/short-url/s7ckoPZRYKRCoDxVrJF8Zb4i1I5.pl) (179 Bytes)

As to editor - I use Emacs. SWI-Prolog has its own [editor](https://www.swi-prolog.org/PceEmacs.html). I think that some people VScode. See also [Program Development Tools](https://www.swi-prolog.org/IDE.html)

---

<div class="post-metadata">

**Author:** ![stephanehaguenau](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@stephanehaguenau](https://swi-prolog.discourse.group/u/stephanehaguenau)\
**Post date:** [February 20, 2021, 7:49am UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/12 "2021-02-20T07:49:27Z")

</div>

> [@peter.ludemann](#):
>
> Emacs

Great it works!  
Thanks a lot for your help and your patience.

Stephane

---

<div class="post-metadata">

**Author:** ![stephanehaguenau](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@stephanehaguenau](https://swi-prolog.discourse.group/u/stephanehaguenau)\
**Post date:** [February 20, 2021, 1:00pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/13 "2021-02-20T13:00:29Z")

</div>

Hi Peter,

I have tried to use the integrated editor of SWI without success.

Here the error message that I have received.

```prolog
?- edit("base1.pl").
% Waiting for editor ... 
% Editor returned failure; skipped make/0 to reload files
true.

```

What shall I do?

Stephane

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 20, 2021, 2:22pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/14 "2021-02-20T14:22:37Z")

</div>

I see. A mac. You need to install Xquartz to get the development tools working. This should popup a new window.

---

<div class="post-metadata">

**Author:** ![stephanehaguenau](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@stephanehaguenau](https://swi-prolog.discourse.group/u/stephanehaguenau)\
**Post date:** [February 20, 2021, 5:02pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/15 "2021-02-20T17:02:27Z")

</div>

Hi jan,

Thank you for your answer.

But now I have another problem: when I try to execute the command edit(“base1.pl”), it closes my Prolog windows!  
I have installed Xquartz.  
Shall I do something else after have installed Xquartz?

Thanks

Stephane

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 20, 2021, 5:32pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/16 "2021-02-20T17:32:50Z")

</div>

Now it may get hard ☹ Which versions of SWI-Prolog, MacOS and XQuartz? You can try to run Prolog in a terminal to get some better feedback. Normally open the MacOS terminal and run this command. If you did not install Prolog you’ll find the same under `/Volumes`

```
 /Applications/SWI-Prolog.app/Contents/MacOS/swipl

```

Now try

```
?- emacs.

```

If it complains something like “[PCE fatal: @display/display: Failed to connect …” your XQuartz is probably not running. If something else, please include the error.

---

<div class="post-metadata">

**Author:** ![stephanehaguenau](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@stephanehaguenau](https://swi-prolog.discourse.group/u/stephanehaguenau)\
**Post date:** [February 20, 2021, 6:01pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/17 "2021-02-20T18:01:15Z")

</div>

Hi jan,

here what I have done:  
open “SWI-Prolog.app/Contents/MacOS/swipl”

?- emacs.  
see the screenshot that I have joined to the post.

Tha

 ![Screenshot](https://global.discourse-cdn.com/free1/uploads/swiprolog/original/2X/8/8754ac31a483a61dca39916d39d6d87b6a5ecd7e.jpeg) nks  
Stephane

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [February 20, 2021, 8:16pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/18 "2021-02-20T20:16:36Z")

</div>

The error message basically says that your X11 (Xquartz) “shared object” file is too old.

You have some options (you might find more possibilities by searching for something like “macos old xquartz” and including the version number you get from `uname -a`:

1. Upgrade your system somehow to get a newer version of /opt/X11/lib/libfreetype.6.dylib (and probably others). (You might be able to just get a newer version of Xquartz, which has the X11 libraries)

2. Create symlinks to fool SWI-Prolog into thinking that it has a newer version of the library (which might or might not work, depending on what has changed between versions). I’ve done this with Linux and SunOS (which depend on naming conventions for tracking version), but never for MacOS, so I don’t know if it’ll work (which might use a different mechanism for tracking library versions) … e.g., something like this (and be sure to keep a note of what you did, so that you can undo it in future):

```prolog
      ( cd /opt/X11/lib/ ;
        sudo ln -s libfreetype.6.dylib libfreetype.7.dylib )

```

1. Rebuild SWI-Prolog for your system (there are instructions for downloading and building at the SWI-Prolog website, but I don’t know how well those instructions work with an old iMac).

2. Find a sufficiently old version of SWI-Prolog that works with your system.

Good luck!

(Personally, I don’t use the edit/1 predict; I run my source editor in one window and my editor in another; but I’m old-fashioned.)

---

<div class="post-metadata">

**Author:** ![stephanehaguenau](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@stephanehaguenau](https://swi-prolog.discourse.group/u/stephanehaguenau)\
**Post date:** [February 20, 2021, 11:10pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/19 "2021-02-20T23:10:33Z")

</div>

Hello Peter, hello Jan,

A great thank you for your support.

a last question : where can I find the reference off all command in SWI for example know how to exit from the trace mode, how to clear the screen and so on.

Thanks

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [February 21, 2021, 6:41pm UTC](https://swi-prolog.discourse.group/t/how-can-i-load-a-base-of-knowledge-with-swi-under-imac/3615/20 "2021-02-21T18:41:51Z")

</div>

> [@stephanehaguenau](#):
>
> how to exit from the trace mode, how to clear the screen and so on.

The manual is quite extensive; for debugging, here’s a link: [SWI-Prolog -- Overview of the Debugger](https://www.swi-prolog.org/pldoc/man?section=debugoverview)
