?- ronri(X), learn(X).

true. X = you

Logic Programming in the Browser

Interactive Editor

editor.pl
1parent(tom, bob).
2parent(tom, liz).
3parent(bob, ann).
4parent(bob, pat).
5
6grandparent(X, Z) :-
7 parent(X, Y),
8 parent(Y, Z).
results
?- grandparent(tom, X).
├─ parent(tom, bob) ✓
├─ parent(bob, ann) ✓
X = ann
├─ parent(bob, pat) ✓
X = pat

Example Programs

Family Tree

parent(tom, bob).
ancestor(X,Y) :-
parent(X,Y).

Load

Puzzle Solver

solve(S) :-
permutation([1,2,3],S),
check(S).

Load

Type Checker

type_of(Ctx,E,T) :-
member(E:T,Ctx).

Load

Documentation

Syntax

+

Facts, rules, queries, and clause notation

% Facts are ground terms
likes(mary, food).
likes(mary, wine).

% Rules define relationships
likes(john, X) :-
likes(mary, X).

% Queries test the knowledge base
?- likes(john, food).
true.

Predicates

+

Built-in and user-defined predicate definitions

% User-defined predicates
mortal(X) :- human(X).
human(socrates).

% Query with unification
?- mortal(Who).
Who = socrates.

Built-ins

+

Arithmetic, list operations, and I/O primitives

% Arithmetic
?- X is 3 + 4 * 2.
X = 11.

% List operations
?- append([1,2],[3,4],L).
L = [1,2,3,4].

Operators

+

Unification, comparison, and control flow operators

% Unification
?- X = f(Y).
X = f(Y).

% Comparison
?- 3 > 2.
true.

% Control: cut
max(X,Y,X) :- X >= Y, !.
max(_,Y,Y).