Interactive notebooks for learning UnifyWeaver through hands-on exploration.
# Ubuntu/Debian
sudo apt-add-repository ppa:swi-prolog/stable
sudo apt-get update
sudo apt-get install swi-prolog
# macOS
brew install swi-prolog
# Windows
# Download from https://www.swi-prolog.org/Download.html
python --version # Should be 3.8+
pip install jupyterlab
# OR
pip install notebook
There are several options for running Prolog in Jupyter. We recommend prolog-jupyter-kernel:
# Install the kernel
pip install prolog-jupyter-kernel
# Install the kernel spec
python -m prolog_kernel.install
# Verify installation
jupyter kernelspec list
# Should show 'prolog' in the list
pip install calysto_prolog
python -m calysto_prolog install
pip install jupyter-swi-prolog
git clone https://github.com/yourusername/UnifyWeaver.git
cd UnifyWeaver/education/notebooks
swipl
?- ['../init'].
% Should load successfully
# From the notebooks directory
cd education/notebooks
# Start JupyterLab
jupyter lab
# OR start Jupyter Notebook
jupyter notebook
.ipynb filesShift+Enter%%bash magic to run shell commands% Load UnifyWeaver
['../init'].
% Define a simple predicate
:- dynamic parent/2.
parent(abraham, isaac).
parent(isaac, jacob).
% Compile to Bash
use_module(unifyweaver(core/stream_compiler)).
stream_compiler:compile_facts(parent, 2, [], BashCode),
writeln(BashCode).
If Jupyter doesn’t show the Prolog kernel:
# Reinstall kernel spec
python -m prolog_kernel.install --user
# Check installation
jupyter kernelspec list
Make sure you’re running notebooks from the education/notebooks directory and that ../init.pl exists:
ls ../init.pl # Should exist
Some kernels require specific SWI-Prolog versions. Check compatibility:
swipl --version
If Prolog kernel installation is problematic, you can still use the notebooks by:
%%bash cells to test generated scriptsRun Prolog queries and see results immediately:
?- factorial(5, F).
F = 120.
Compile predicates and view generated Bash code in-place:
compile_recursive(factorial/2, [], BashCode),
writeln(BashCode).
Test Bash scripts directly in the notebook:
%%bash
source ../output/factorial.sh
factorial 10 ""
Generate DOT graphs for call graph visualization:
build_call_graph([is_even/1, is_odd/1], Graph),
generate_dot(Graph, DotCode).
Recommended order:
Ctrl+S) are good practiceKernel → Restart in the menuCell → All Output → Clear to clean upRun → Run All Cells to execute the entire notebookFound an issue or have an improvement? Please:
These notebooks are part of the UnifyWeaver education materials and are licensed under:
See parent directory LICENSE files for details.
For questions or help:
Happy learning! 🎓