Hello, would you help a beginner?

Dear teachers, In my senior years I found out that this science is so amazing and I am just starting to scratch the very tip of the iceberg. In the last four years, with the help of the internet alone I’ ve been able to build two 3D printers and 7 drones which I incredibly made to work even though I had to modify some queries without having any basic knowledge in coding with arduino. Now, I am trying to learn the very basics of SWI Prolog with Linux in a Raspberry pi. It’s been frustrating since I am using a book called “Beginning artificial Intelligence with the Raspberry Pi” ; I can’t start to practice the first exercises called "Satellites.pl, office.pl, animal.pl., etc. Because after several weeks of trying and studying, I can’t even find them in this SWI Prolog tutorial as such book suggest. I don’t mean to make you lost your time with such an old apprentice like me but I’d appreciate any help or hint that you can provide me. Thank You, Victor Rodas

I assume you already cloned or downloaded the repo with the books code?

But of those three Prolog files you mention, the repo only contains animal.pl.

1 Like

Thank you pmoura. I’m working on it. Let see what happens.
2/23/19: I downloaded those that you suggested and am playing with them. I decompressed , put them on files and so fort. As up today SWI-Prolog doesn’t obey any of my commands, like this:
?- [office].
ERROR: source_sink 'office does not exist…or
[trace] ?- help(office).
Call: (7) online_help:help (office) ? unknown option (h for help)
Call: (7) online_help:help (office) ?

I bought and am reading the book “Prolog programming for artificial intelligence” by professor Ivan Bratko, 1989" and will advance step by step until I get SWI - Prolog to start obeying my commands. I know I’m missing something and need to find out what it is.
Thank you again,
Victor

Hi,

Building stuff like that sounds like a great way to spend one’s senior years!

My advice would be to learn Prolog first, before you start learning using it for programming the Rasperry Pi. You may want to check out tutorial resources such as Learn Prolog Now [1] or Markus Triskas book [2] (Markus’ book is more modern and in many ways better than Learn Prolog Now, but depending on your background it might be easier to start with Learn Prolog Now.)

My second advice would be to use SWISH [3], an online IDE which allows you to edit and then run most Prolog programs without even installing SWI-Prolog locally. It also allows you to generate a URL to your program so that others, if they have the link, can read, edit and run your program (but only permanently modify it you allow them too - although they can always clone your program). You can even chat with other users from inside SWISH.

My third advice would be to use StackOverflow [4] to you advantage. Using the link generated in SWISH in your StackOverflow question might be a good idea.

[1] http://www.learnprolognow.org
[2] https://www.metalevel.at/prolog
[3] https://swish.swi-prolog.org
[4] https://stackoverflow.com/questions/tagged/prolog

Hope this helps and congrats to having started with Prolog!

  • Torbjörn
1 Like

Torbjorn,
I really appreciate you by taking time to advise me. Your ideas are very helpful and thinking about it I just bought this old book “Prolog programming for artificial intelligence” by professor Ivan Bratko, 1989. and I am getting very excited with it. It’s like an easily explained book (at least in the preliminary pages). Of course, I’m going to read all that you recommended. Right now, I would be happy if SWI-Prolog only responded to one of my commands, for instance:
?- [office]
ERROR:source_sink ‘office’ does not exist
?- trace,
true.
Or
[trace] ?- help(office).
Call: (7) online_help:help (office) ? unknown option (h for help)
Call: (7) online_help:help (office) ?

I downloaded all files pertinent to the Raspberry AI book and decompressed them and put them in files and all so on. I think that I may be missing few easy steps that you the experienced ones do as a matter of fact and take for granted while I got no idea which they are. I’l continue studying and with patience and some help I’ll build and put the robot to work. (I need tho think positively).
Than you again,
Victor Rodas

For ?- [office]. to work you need a file office.pl in the current directory. Now, I have no clue how you started SWI-Prolog, but you can find its notion of the current directory using ?- pwd.

Typically, open a shell in the directory where the Prolog files are and run

swipl office.pl

That should work for not very old versions. Unfortunately some of the distros ship with ancient versions. In that case you can use swipl -s office.pl.

If you do ?- trace. and then ?- help(office). you start tracing help. No clue what you typed as a response, but typing h gives you the options. Most likely you do not want to debug help though and you cannot expect it to say anything meaningfully about your file, especially if this file is not at a place Prolog can find it.

1 Like

Thanks a lot Jan.
I followed up with your advise and this is what I found:

?- pwd,
%  /home/pi/        (in green characteres, it feels good)
true.

Then, I tried:

swipl office.pl 
Warning: package bddem: no binary for architecture armhf
ERROR: prolog initialization failed 
ERROR: source sink "office.pl" does not exist

I really hope that this says something to you.

My best Regards,

Victor

Running swipl office.pl needs a file office.pl in the current directory. I guess you created or downloaded this file from somewhere?

As a side note, you seem to have installed pack bddem, but this pack does not provide Pi compatible binaries. You need to run ?- pack_rebuild(bddem). and possibly install dependencies before doing so. See the pack home page.

1 Like

Jan, I did what your recommended and below is what I got. Do you think that would be an option to erase, format, and upload the sd card with raspbian and swi-prolog again? Or delete only certain programs? which ones would you recommend to delete?
You know, at the very beginning when I uploaded like this: sudo apt-get install swi prolog; there was not that “Warning package bddm” message but then I started uploading more programs hoping for a miracle to happen and the warning started showing up.
Well, there are not miracles in this science but only study and that’s what I’m doing right now. Any tip will be always appreciated.

pi@raspberrypi:~ $ swipl
Warning: Package bddem: no binary for architecture armhf
Welcome to SWI-Prolog (Multi-threaded, 32 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).

?- pack_rebuild(bddem).
ERROR: pack `bddem' does not exist

You have a quite old version. That happens in many of the distributions. You can install from source to get the latest. Fot basic usage it probably doesn’t matter too much. You can ignore the bddem message if you do not need this. You can also delete the package by removing its directory. Most likely that is in ~/lib/swipl/pack/bddem.

1 Like

Do you mean that I have the old version of raspbian? If so what source would you recommend? I understand, if that was the case, that I had to remove it from the SD card and format it in order to download again, right?

Also, got this:

pi@raspberrypi:~ $ sudo apt-get remove ~/lib/swipl/pack/bddem.
Reading package lists... Done
E: Unsupported file /home/pi/lib/swipl/pack/bddem. given on commandline
pi@raspberrypi:~ $

Raspbian ships with a rather old version of SWI-Prolog. If you just want the basics, that is fine. If you want to use recent stuff, you should download the source and build it from source. That is quite doable on a Pi3. On older Pis is requires a lot of patience :slight_smile:

Fot now, I’d just stick with the Raspbian version … If you find stuff in the online manual that is not in your version and you want to use it, it is time to consider updating.

This is not a Raspbian package. Just use rm -r ~/lib/swipl/pack/bddem.

1 Like

pi@raspberrypi:~ $ rm -r ~/lib/swipl/pack/bddem.
rm: cannot remove ‘/home/pi/lib/swipl/pack/bddem.’: No such file or directory

?- office.pl.
ERROR: Type error: dict' expected, foundoffice’ (an atom)
?- trace.
true.

[trace] ?- supervises(who, green).
ERROR: toplevel: Undefined procedure: supervises/2 (DWIM could not correct goal)
[trace] ?- office.pl.
Call: (8) ‘.’(office, pl, _G3194) ? creep
ERROR: Type error: dict' expected, foundoffice’ (an atom)
Exception: (8) ‘.’(office, pl, _G3194) ? creep
[trace] ?-

Jan,
It seems to me like the program is trying to interact. I see that “Call:(8) ‘.’(office,pl, _G3194) ? creep” like part of it. However, my textbook has only Call: (6) and Call: (7) whatever that means.

Sorry for being a nuisance but I keep reading my books so I can learn more about the language.
Vic

MORE:
[debug] [1] ?- L:
| stop.
ERROR: current_prolog_flag/2: Type error: atom' expected, found_G8554:unknown’ (a compound)
Exception: (13) correct_goal(stop, _G8502, [‘L’=_G8502], _G8576) ? creep
[debug] [1] ?- w:
|
| stop.
ERROR: toplevel: Undefined procedure: w:stop/0 (DWIM could not correct goal)
[debug] [1] ?- -:

This looks wrong already. It probably should be:

?- [office].
true

… but I might be missing the context.

1 Like

Thanks Boris,
This is what I’ve got.
?- [office].
ERROR: source_sink `office’ does not exist
?-
Yes. there is an error from the beginning. have no clue about the cause. I’ve tried multiple times and the SWI Prolog doesn’t respond positively.

You are missing the office.pl file in the directory from which you start swipl. Download the file by going to this link:

https://raw.githubusercontent.com/Apress/beg-artificial-intelligence-w-raspberry-pi/master/Chapter%203/office.pl

Then right click, and choose Save.. or Save as.. (whatever your browser provides).

Remember you have to save it in the same directory from which you start swipl. Perhaps it is your home directory.

First type:

?- ls.

and make sure office.pl shows up.
After you see it then you can do:

?- [office].
1 Like

Note that there seems to be a typo in the code listing. I see:

/*office program */
adminWorker(black).
admnWorker(white).

officeJunior(green).

manager(brown).
manager(grey).
supervises(X,Y) :- manager(X), adminWorker(Y).
supervises(X,Y) :- adminWorker(X), officeJunior(Y).
supervises(X,Y) :- manager(X), officeJunior(Y).

On line 3, it should be adminWorker, like above, not admnWorker (the “i” is missing).

1 Like

Boris,
I did what you suggested and Now it shows up in the listing. However is not opening yet. I think that I am close thanks to you. Spasibo.
Desktop/
% Documents/
% Downloads/
% humidity-2019-02-21-18-38-09.py
% humidity-2019-02-21-18-38-09.py.bz2
% joystick_events-2019-02-21-18-36-46.py
% lib/
% MagPi/
% Mail/
% Music/
% office.pl
% Pictures/
% Public/
% rainbow-2019-02-21-18-37-31.py
% Scratch/
% Templates/
% UNO/
% Videos/
% Wolfram Mathematica/
true.

?- [office.pl].
ERROR: Type error: dict' expected, foundoffice’ (an atom)
?-

You still need to write it correctly and not write it incorrectly.

?- [office].

is correct. This is incorrect:

?- [office.pl]. % incorrect!

Spot the 3 differences!

You should also use code blocks when you post such things. Put 4 spaces at the beginning of each line of code, or make code block by using 3 backticks on the top and the bottom of the code block:

```
this is a code block
```
1 Like