Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Prolog
loop :- loop.

?- loop.

loop succeeds if loop succeeds, so when we ask the top level if loop succeeds, it proceeds to ask if loop succeeds.
repeat, write("hello\n").

This a bit strange, repeat is a predicate that will always succeed, that is always true.
?- repeat, false.

% repeat/0 is built-in, but could be defined like this:
repeat.
repeat :- repeat.

`repeat/0` succeeds an infinite number of times, and each time is immediately foiled by false/0. The default execution strategy just tries clauses in order from left to right so this induces an infinite loop.
loop
   null;
end loop;

null; means "do nothing"

New implementation...
< >
programming-idioms.org