Skip to content
Hello, Prolog
step 1/5

Reading — step 1 of 5

Learn

~1 min readFacts and Rules

Prolog (PROgrammation en LOGique) was designed in 1972 at the University of Marseille. It's a declarative language — you state what's true, not how to compute. The Prolog engine searches for proofs.

A minimal Judge0-runnable Prolog program needs an initialization directive:

:- initialization(main).

main :-
    write('Hello, Prolog!'),
    nl.
  • :- initialization(main). tells Prolog to call main on startup
  • A predicate is name :- body. (body uses , for AND, . to end)
  • write/1 prints; nl outputs a newline
  • Strings are typically atoms in single quotes in classic Prolog
  • Comments use %

Variables start with uppercase or _. Lowercase identifiers are atoms (constants).

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…