
Country Logic is a small command-line application for exploring country data with Rust and Prolog. It fetches names, regions, populations, ISO codes, and land borders from the REST Countries API, converts that data into Prolog facts, and evaluates four simple logical rules with an embedded Scryer Prolog engine.
The project is intentionally compact. Rust handles the command-line interface,
HTTP requests, JSON decoding, and Prolog integration. The rules in rules.pl
handle country relationships and population queries.
Copy the example environment file:
cp .env.example .env
Then replace the placeholder in .env with your API key:
RESTCOUNTRIES_API_KEY=your_key
The .env file is ignored by Git. An existing environment variable takes
precedence over the value in that file.
List all countries or regions:
cargo run -- countries
cargo run -- regions
Run country queries:
cargo run -- large
cargo run -- region Americas
cargo run -- more-populous Brazil
cargo run -- neighbors Brazil
Country arguments accept an English name or a three-letter ISO code. Lists are sorted alphabetically and contain no duplicates.
large_country(Country) finds countries with more than 100 million people.country_in_region(Country, Region) finds countries in a region.more_populous(CountryA, CountryB) finds countries with a larger population.borders(Country, Neighbor) finds countries that share a land border.src/main.rs defines the CLI and connects Rust to Prolog.src/query_countries.rs fetches and decodes the required API data.rules.pl contains the four Prolog rules..env.example documents the required environment variable.Run the automated checks with:
cargo test
cargo clippy --all-targets -- -D warnings
10 commits
Hacker News (1)
Rust
95.3%
Prolog
4.7%

Country Logic is a small command-line application for exploring country data with Rust and Prolog. It fetches names, regions, populations, ISO codes, and land borders from the REST Countries API, converts that data into Prolog facts, and evaluates four simple logical rules with an embedded Scryer Prolog engine.
The project is intentionally compact. Rust handles the command-line interface,
HTTP requests, JSON decoding, and Prolog integration. The rules in rules.pl
handle country relationships and population queries.
Copy the example environment file:
cp .env.example .env
Then replace the placeholder in .env with your API key:
RESTCOUNTRIES_API_KEY=your_key
The .env file is ignored by Git. An existing environment variable takes
precedence over the value in that file.
List all countries or regions:
cargo run -- countries
cargo run -- regions
Run country queries:
cargo run -- large
cargo run -- region Americas
cargo run -- more-populous Brazil
cargo run -- neighbors Brazil
Country arguments accept an English name or a three-letter ISO code. Lists are sorted alphabetically and contain no duplicates.
large_country(Country) finds countries with more than 100 million people.country_in_region(Country, Region) finds countries in a region.more_populous(CountryA, CountryB) finds countries with a larger population.borders(Country, Neighbor) finds countries that share a land border.src/main.rs defines the CLI and connects Rust to Prolog.src/query_countries.rs fetches and decodes the required API data.rules.pl contains the four Prolog rules..env.example documents the required environment variable.Run the automated checks with:
cargo test
cargo clippy --all-targets -- -D warnings
Hacker News (1)
10 commits
Rust
95.3%
Prolog
4.7%