Skip to main content

Prolog Hello World

Open In Colab Open In Binder


Prolog is intended primarily as a declarative programming language: the program logic is expressed in terms of relations, represented as facts and rules. A computation is initiated by running a query over these relations. Prolog is well-suited for specific tasks that benefit from rule-based logical queries such as searching databases, voice control systems, and filling templates. In this example we will run a hello world prolog script on bacalhau

Running Locally​

Install swipl

sudo add-apt-repository ppa:swi-prolog/stable
sudo apt-get update
sudo apt-get install swi-prolog
 Comprehensive Prolog implementation with extensive libraries and development tools.   Primarily targetted at teaching, RDF processing and web-related tasks, such as creating web services or analysing web content.

Official PPAs for SWI-Prolog. See for further information.
More info:
Hit:1 bionic-cran40/ InRelease
Hit:2 bionic InRelease
Hit:3 bionic InRelease
Get:4 bionic-security InRelease [88.7 kB]
Ign:5 InRelease
Hit:6 InRelease
Hit:7 Release
Get:8 bionic-updates InRelease [88.7 kB]
Hit:9 bionic InRelease
Hit:10 bionic InRelease
Get:11 bionic-backports InRelease [83.3 kB]
Hit:12 bionic InRelease
Hit:13 bionic InRelease
Fetched 261 kB in 2s (141 kB/s)
Reading package lists...
Hit:1 bionic-cran40/ InRelease
Ign:2 InRelease
Hit:3 InRelease
Hit:4 Release
Hit:6 bionic InRelease
Get:7 bionic-security InRelease [88.7 kB]
Hit:8 bionic InRelease
Hit:9 bionic InRelease
Get:10 bionic-updates InRelease [88.7 kB]
Get:11 bionic-backports InRelease [83.3 kB]
Hit:12 bionic InRelease
Hit:13 bionic InRelease
Hit:14 bionic InRelease
Fetched 261 kB in 5s (57.4 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
swi-prolog is already the newest version (8.4.3-0-bionicppa2).
The following package was automatically installed and is no longer required:
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.

Create a file called

The following script prints ‘Hello World’ to the stdout

hello_world :- write('Hello World'), nl,

Running the script

swipl -q -s -g hello_world
Hello World

After the script has run successfully locally we can now run it on bacalhau

For that we upload our script to IPFS since the script is only present locally ipfs add

Using IPFS cli

!tar xvfz go-ipfs_v0.4.2_linux-amd64.tar.gz
!mv go-ipfs/ipfs /usr/local/bin/ipfs
!ipfs init
!ipfs cat /ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme
!ipfs config Addresses.Gateway /ip4/
!ipfs config Addresses.API /ip4/
!nohup ipfs daemon > startup.log &
--2022-11-12 08:44:36--
Resolving (, 2602:fea2:3::1
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7642422 (7.3M) [application/gzip]
Saving to: ‘go-ipfs_v0.4.2_linux-amd64.tar.gz.4’

go-ipfs_v0.4.2_linu 100%[===================>] 7.29M --.-KB/s in 0.04s

2022-11-12 08:44:36 (206 MB/s) - ‘go-ipfs_v0.4.2_linux-amd64.tar.gz.4’ saved [7642422/7642422]

Error: ipfs daemon is running. please stop it to run this command
Use 'ipfs init --help' for information about this command
Hello and Welcome to IPFS!

██╗██████╗ ███████╗███████╗
██║██████╔╝█████╗ ███████╗
██║██╔═══╝ ██╔══╝ ╚════██║
██║██║ ██║ ███████║
╚═╝╚═╝ ╚═╝ ╚══════╝

If you're seeing this, you have successfully installed
IPFS and are now interfacing with the ipfs merkledag!

| Warning: |
| This is alpha software. Use at your own discretion! |
| Much is missing or lacking polish. There are bugs. |
| Not yet secure. Read the security notes for more. |

Check out some of the other files in this directory:

./quick-start <-- usage examples
./readme <-- this file
nohup: redirecting stderr to stdout
!ipfs add
added QmYq9ipYf3vsj7iLv5C67BXZcpLHxZbvFAJbtj7aKN5qii

Copy the CID of the file which in this case is QmYq9ipYf3vsj7iLv5C67BXZcpLHxZbvFAJbtj7aKN5qii

Since the data Uploaded To IPFS isn’t pinned or will be garbage collected

The Data needs to be Pinned, Pinning is the mechanism that allows you to tell IPFS to always keep a given object somewhere, the default being your local node, though this can be different if you use a third-party remote pinning service.

Using NFTup

NFT.Storage (Recommneded Option)

Upload files and directories with NFTUp

To upload your dataset using NFTup just drag and drop your directory it will upload it to IPFS


Running on bacalhau

We will use the official swipl docker image

!curl -sL | bash
Your system is linux_amd64
No BACALHAU detected. Installing fresh BACALHAU CLI...
Getting the latest BACALHAU CLI...
Installing v0.3.11 BACALHAU CLI...
Downloading ...
Downloading sig file ...
Verified OK
Extracting tarball ...
NOT verifying Bin
bacalhau installed into /usr/local/bin successfully.
Client Version: v0.3.11
Server Version: v0.3.11


%%bash --out job_id
bacalhau docker run \
-v QmYq9ipYf3vsj7iLv5C67BXZcpLHxZbvFAJbtj7aKN5qii:/ \
--wait \
--id-only \
swipl \
-- swipl -q -s -g hello_world

then we will mount the script to the container using the -v flag

-v < CID >:/< name-of-the-script >

Swipl flag

-q running in quiet mode

-s load file as a script in this case we want to run the script

-g is the name of the function you want to execute in this case its hello_world

bacalhau list --id-filter ${JOB_ID} --wide
 CREATED            ID                                    JOB                                                    STATE      VERIFIED  PUBLISHED                                            
 22-11-12-08:00:51  ddd22db1-61c7-4302-bbe2-f38f8ffa2f44  Docker swipl swipl -q -s -g hello_world  Completed   /ipfs/QmYnaUZLWmbRTJzpx6kgxoAVT3ZAmhqWY6qWZm33v8PjNm 

Where it says "Completed", that means the job is done, and we can get the results.

To find out more information about your job, run the following command:

bacalhau describe ${JOB_ID}
rm -rf results && mkdir -p results
bacalhau get $JOB_ID --output-dir results
Fetching results of job 'ddd22db1-61c7-4302-bbe2-f38f8ffa2f44'...
Results for job 'ddd22db1-61c7-4302-bbe2-f38f8ffa2f44' have been written to...

2022/11/12 08:01:59 failed to sufficiently increase receive buffer size (was: 208 kiB, wanted: 2048 kiB, got: 416 kiB). See for details.

Viewing the outputs

cat results/combined_results/stdout
Hello World