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 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
Download from the command line
curl -L -o sample.pro https://files.samplefiles.com/code/prolog/sample.prowget https://files.samplefiles.com/code/prolog/sample.prohttps://files.samplefiles.com/code/prolog/sample.proprintf '%s %s\n' def4e36f58fcb04c042b64d1f9299bc335248221aa27aecb7ebd9ffbe36a1605 sample.pro | shasum -a 256 -cOr check the download in your browser with the checksum calculator.