8. Shen Prolog
TBoS p.343-361, SD
Here are the member, reverse and append functions in Shen Prolog.
(0-) (defprolog member
X [X | _] <--;
X [_ | Y] <-- (member X Y);)
(fn member)
(1-) (defprolog rev
[] [] <--;
[X | Y] Z <-- (rev Y W) (conc W [X] Z);)
(fn rev)
(2-) (defprolog conc
[] X X <--;
[X | Y] Z [X | W] <-- (conc Y Z W);)
(fn conc)
(3-) (prolog? (member 1 [1 2]))
true
(4-) (prolog? (member 0 [1 2]))
false
(5-) (prolog? (member X [1 2]))
true
(6-) (prolog? (member X [1 2]) (return X))
1
(7-) (prolog? (rev [1 2] X) (return X))
[2 1]
|
|