Code · 1 file

Sample Prolog File

SWI-Prolog facts, rules and formatted output. Every language sample implements the same small program so you can compare them side by side.

Prolog · 574 B

Sample Prolog file

An idiomatic Prolog example — the same customer program (or, for hardware languages, a small counter design) we offer in every language.

CC0 · free for any use · Verified by an independent tool · Report a problem

sample.pro — first linesProlog
% Sample Prolog program (SWI-Prolog) — samplefiles.com
customer(1, 'Ada', 12500.0).
customer(2, 'Grace', 830.5).
customer(3, 'Linus', 10000.0).

vip(Id) :- customer(Id, _, Balance), Balance >= 10000.

total_balance(Total) :-
    findall(B, customer(_, _, B), Bs),
    sum_list(Bs, Total).

main :-
    forall(customer(Id, Name, Balance),
           (   ( vip(Id) -> Tag = 'VIP' ; Tag = '' ),
               format("~w~t~6| ~t~2f~17| ~w~n", [Name, Balance, Tag])
           )),
    total_balance(Total),
    format("Total: ~2f~n", [Total]).

:- initialization(main, main).

File details

Size
574 B (574 bytes)
MIME type
text/x-prolog
SHA-256
def4e36f58fcb04c042b64d1f9299bc335248221aa27aecb7ebd9ffbe36a1605
MD5
ac200c60b52279f07ae8232c0093dfe8

Download from the command line

curl -L -o sample.pro https://files.samplefiles.com/code/prolog/sample.pro

Or check the download in your browser with the checksum calculator.