List odd-even

Description

Learning about odd-length and even-length simultaneously.

Source: PROLOG programming for artificial intelligence, 3rd Edition, Harlow, 2001, ISBN 0-201-40375-7.

Download

Program source code: list_odd-even.pl

Listing

% Figure 19.8  Learning about odd-length and even-length simultaneously.
 
% Inducing odd and even length for lists
 
backliteral( even( L), [ L:list], []).
backliteral( odd( L), [ L:list], []).
 
term( list, [X|L], [ X:item, L:list]).
term( list, [], []).
 
prolog_predicate( fail).
 
start_clause([ odd( L) ] / [ L:list]).
start_clause([ even( L) ] / [ L:list]).
 
ex( even( [])).
ex( even( [a,b])).
ex( odd( [a])).
ex( odd( [b,c,d])).
ex( odd( [a,b,c,d,e])).
ex( even( [a,b,c,d])).
 
nex( even( [a])).
nex( even( [a,b,c])).
nex( odd( [])).
nex( odd( [a,b])).
nex( odd( [a,b,c,d])).

Comments

pl/prolog/pllib/list_odd-even.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0