// h18.9/29 (鈴) package exp; import tiny_prolog.Core; /** Core の実験 */ public class P0 extends Core { static Goal _(Pred pred, Object... terms) { return new Goal (pred, terms); } static Goals __(Goal goal) { return new Goals (goal, null); } static Pair cons(Object car, Object cdr) { return new Pair (car, cdr); } /** append 述語を定義し,実行結果を表示する。 */ public static void main(String[] args) { Var A = new Var ("A"); Var X = new Var ("X"); Var Y = new Var ("Y"); Var Z = new Var ("Z"); Pred append = new Pred ("append"); // append([], A, A). _(append, null, A, A).si(null); // append([A|X], Y, [A|Z]) :- append(X, Y, Z). _(append, cons(A, X), Y, cons(A, Z)).si(__(_(append, X, Y, Z))); // ?- append(X, Y, [1, 2, 3]). Goals goals = __(_(append, X, Y, cons(1, cons(2, cons(3, null))))); for (Env env: goals) { Object x = env.get(X); Object y = env.get(Y); System.out.println("x = " + x + ", y = " + y); } } }