%%% -*- prolog -*-

%%% Execution Model

%%% predicate = procedure BUT ...
%%%                 - zero or more "results"
%%%                 - can fail to terminate

%%% data structure = "terms", like s-expression WITH HOLES
%%% HOLES are "logic variables"
%%% logic variables can be equal without knowing their values

%%% this is set up via UNIFICATION


%% X = Y is the same as unify(X, Y) with the definition:
%% unify(X, X).

%% infix syntax ..., convert to prefix w/ '...'

%% | ?- foo(a, X) = foo(Y, b).
%% | ?- '='(foo(a, X), foo(Y, b)). 

%% [X | Ys] is syntactic sugar for .(X, Ys)
%% [X , Y, Zs] is syntactic sugar for .(X, .(Y, Zs))

%% Controlling the search:
%%  - predicate fail, always fails.  Could define with:
%%    fail :- a=b.
%%  - cut (ICKY, BREAKS EXECUTION MODEL)
%%    denoted with: !

color(X) :- member(X, [red, orange, green, blue, indigo, violet]).

%% positional notation
%% change([1, 5, 10, 20, 50], amount)
ischange([C1, C5, C10, C20, C50], T)
  :- T is C1 + 5*C5 + 10*C10 + 20*C20 + 50*C50.

le(0, Max) :- Max >= 0.
le(I, Max) :- Max >= 0, Max1 is Max-1, le(J, Max1), I is J+1.
