https://img.shields.io/badge/-FreeBSD-%23AB2B28?style=flat&logo=freebsd&logoColor=white
https://img.shields.io/badge/Org-literate%20programming-77aa99?style=flat&logo=org&logoColor=white
A comprehensive workshop for learning Scryer Prolog, a modern ISO Prolog implementation written in Rust. This repository uses literate programming with Org-mode for an integrated learning and development experience.
Scryer Prolog is a free software ISO Prolog system that aims to be:
- An industrial-strength production environment
- A testbed for bleeding-edge research in logic and constraint programming
- A modern implementation with advanced features like tabling, constraints, and FFI
This workshop provides:
- Automated setup and build tools via Makefile
- Comprehensive examples from basics to advanced topics
- Literate programming approach with Org-mode
- Full Emacs configuration for Rust and Prolog development with LSP
- FreeBSD 14.3-RELEASE amd64
- Also works on Linux, macOS, and Windows
- Emacs (for org-mode tangling)
- Rust toolchain (cargo)
- Git
# Check dependencies
make test-deps
# Install dependencies (if needed)
make install-deps
# Option 1: Install via cargo (recommended)
make setup
# Option 2: Build from source in ~/opt
make build-from-source
make update-path
# Tangle org files to generate Prolog code
make tangle
# Start Scryer Prolog REPL
make run
# Or run a specific file
make run-file FILE=hello.pl. ├── Makefile # Build and setup automation ├── README.org # This file ├── setup.org # Main workshop content (literate programming) ├── scryer-emacs-config.el # Emacs configuration for development │ ├── Generated files (from setup.org): ├── hello.pl # Hello World and basic examples ├── facts.pl # Facts and queries (family relationships) ├── lists.pl # List operations ├── recursion.pl # Recursive predicates ├── scryer_features.pl # Scryer-specific features (DCGs, format, etc.) ├── constraints.pl # CLP(Z) constraint examples ├── tabling.pl # Tabling for memoization └── setup.sh # Installation scripts
make help- Display help message with all available targetsmake test-deps- Test for required dependenciesmake install-deps- Install required dependencies (emacs, rust)
make setup- Complete setup (tangle + install scryer-prolog via cargo)make build-from-source- Build Scryer Prolog from source in ~/optmake update-path- Add Scryer Prolog to PATH in shell config
make tangle- Tangle all org-mode files in current directorymake tangle-file FILE=<file.org>- Tangle a specific org filemake run- Run Scryer Prolog REPLmake run-file FILE=<file.pl>- Run Scryer Prolog with a file
make clean- Remove generated files (.pl, .sh, etc.)make clean-build- Clean build artifacts in ~/opt/scryer-prolog
The setup.org file contains the complete workshop material, organized as:
- What is Scryer Prolog?
- System requirements
- Installation methods (cargo, build from source)
- Hello World example
- Running your first program
- Basic Prolog queries
- Exercise 1: Facts and queries (family relationships)
- Exercise 2: Lists (member, length, append, reverse, sum)
- Exercise 3: Recursion (factorial, fibonacci, ranges)
- Exercise 4: Scryer-specific features (DCGs, format, libraries)
- Constraint Logic Programming: CLP(Z) examples and N-Queens problem
- Tabling: Efficient memoization with tabled predicates
- Module system and library usage
- Official documentation links
- Learning resources (The Power of Prolog, Learn Prolog Now!)
- Community information (GitHub, IRC)
The scryer-emacs-config.el file provides a complete development environment:
- LSP Support: Full Language Server Protocol integration for Rust and Prolog
- Rust Development: rust-mode, cargo integration, rust-analyzer
- Prolog Development: prolog-mode configured for Scryer, sweeprolog integration
- Literate Programming: Org-mode with babel for tangling
- Productivity Tools: Company (auto-completion), Flycheck (syntax checking)
- Project Management: Projectile, Magit (Git integration)
- UI Improvements: which-key, helpful, rainbow-delimiters
Add to your ~/.emacs or ~/.emacs.d/init.el:
(load-file "/path/to/scryer-prolog-workshop/scryer-emacs-config.el")C-c w t- Tangle current org file and prepare to runC-c w s- Check if required tools are installedC-c w p- Run Prolog REPLC-c l- LSP command prefixC-x g- Magit status
This workshop uses literate programming with Org-mode:
- Edit: Modify
setup.orgor create new.orgfiles - Tangle: Run
make tangleto extract code blocks into.plfiles - Test: Run programs with
make run-file FILE=hello.pl - Iterate: Refine your code and documentation together
- Use
C-c C-v tin Emacs to tangle the current file - Use
:tangle filename.plto specify output file - Use
:tangle noto prevent tangling a code block - Code blocks support syntax highlighting and editing in native mode
cargo install --locked scryer-prolog# Clone and build in ~/opt
make build-from-source
# Add to PATH
make update-path
# Or manually:
export PATH="$HOME/opt/scryer-prolog/target/release:$PATH"git clone https://github.com/mthom/scryer-prolog.git
cd scryer-prolog
cargo build --release
# Binary: target/release/scryer-prolog$ scryer-prolog hello.pl
?- say_hello.
Hello, World!
Welcome to Scryer Prolog!
Prolog is awesome!
?- greet('Alice').
Hello, Alice!
?- greeting(X).
X = "Hello, World!" ;
X = "Welcome to Scryer Prolog!" ;
X = "Prolog is awesome!".$ scryer-prolog -g main hello.pl
=== Scryer Prolog Workshop ===
Hello, World!
Available greetings:
- Hello, World!
- Welcome to Scryer Prolog!
- Prolog is awesome!- Website: https://www.scryer.pl/
- GitHub: https://github.com/mthom/scryer-prolog
- Library Docs: https://www.scryer.pl/documentation.html
- The Power of Prolog by Markus Triska
- Learn Prolog Now!
- SWI-Prolog Documentation (mostly compatible)
- GitHub Issues: https://github.com/mthom/scryer-prolog/issues
- IRC: #scryer on Libera.Chat
Scryer includes built-in CLP(B) and CLP(Z) libraries:
:- use_module(library(clpz)).
?- X #> 0, X #< 10, X #= Y + 3, Y #= 5.
X = 8, Y = 5.Automatic memoization for recursive predicates:
:- use_module(library(tabling)).
:- table fib/2.
fib(0, 0).
fib(1, 1).
fib(N, F) :- N > 1, N1 is N - 1, N2 is N - 2,
fib(N1, F1), fib(N2, F2), F is F1 + F2.Built-in support for parsing:
sentence --> noun_phrase, verb_phrase.
noun_phrase --> determiner, noun.
verb_phrase --> verb, noun_phrase.
?- phrase(sentence, [the, cat, chases, a, dog]).
true.# FreeBSD
sudo pkg install emacs
# macOS
brew install emacs
# Linux
sudo apt-get install emacs # Debian/Ubuntu
sudo dnf install emacs # Fedora# Install via rustup (recommended)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
# Or via package manager (may be outdated)
sudo pkg install rust # FreeBSD
brew install rust # macOS# Update Rust to latest stable
rustup update stable
# Clean and rebuild
cd ~/opt/scryer-prolog
cargo clean
cargo build --release- Ensure Emacs is installed:
which emacs - Check org-mode is available:
emacs --batch --eval "(require 'org)" - Verify .org file syntax is correct
This is a workshop repository for learning. Feel free to:
- Add your own exercises to
setup.org - Create new
.orgfiles for specific topics - Share improvements to the Makefile or Emacs configuration
- Submit issues or pull requests
This workshop material is provided as-is for educational purposes.
Scryer Prolog itself is licensed under BSD-3-Clause. See: https://github.com/mthom/scryer-prolog/blob/master/LICENSE
- Scryer Prolog: Mark Thom and contributors
- The Power of Prolog: Markus Triska for excellent learning resources
- Emacs: For enabling literate programming with Org-mode
- Rust: For providing a solid foundation for Scryer Prolog
—
Built with: Org-mode • Scryer Prolog • Rust • Emacs • FreeBSD
Happy Prologging! 🚀