%% Copyright (C) 2017, 2019 Dennis J. Darland %% This file is part of darland's philosophy. %% darland's philosophy is free software: you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published by %% the Free Software Foundation, either version 3 of the License, or %% (at your option) any later version. %% darland's philosophy is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty of %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %% GNU General Public License for more details. %% You should have received a copy of the GNU General Public License %% along with darland's philosophy. If not, see . %% check_arity(3, A, B, C) :- A :\== nop, B :\== nop, C :\== nop. %% check_arity(2, A, B, nop) :- A :\== nop, B :\== nop. %% check_arity(1, A, nop, nop) :- A :\== nop. %% check_arity(0, nop , nop, nop). %% I had help from Hassan Ait-Kaci on the apply_predicate predicate. different(A, B) :- A :\== B. %% type_p1(Type, Type_p1) :- Type_p1 = Type + 1. %% type_p2(Type, Type_p2) :- Type_p2 = Type + 2. %% type_p3(Type, Type_p2) :- Type_p2 = Type + 3. %% write_type(Loc, Type) :- write(Loc, 'Type = ', Type, '|'). write_time(Ignore) :- write(system("date")). %% write_stats(Ignore) :- write('will be stats someday'). write_stats(Ignore) :- write("I am not sure of units here\n", "Clock Time ", real_time/1000000000.0, " Seconds\n", "CPU Time ", cpu_time * 1000.0, " Milliseconds\n"). apply_predicate(Logical_Form, Type, Arity, Relation, A_object, B_object, C_object, D_object, E_object, F_object, G_object, H_object, I_object, J_object, K_object, L_object, M_object, N_object, O_object, P_object, Q_object, R_object, S_object, T_object, U_object, V_object, W_object, X_object, Y_object, Z_object) :- P = Relation, P.1 = A_object, P.2 = B_object, P.3 = C_object, P.4 = D_object, P.5 = E_object, P.6 = F_object, P.7 = G_object, P.8 = H_object, P.9 = I_object, P.10 = J_object, P.11 = K_object, P.12 = L_object, P.13 = M_object, P.14 = N_object, P.15 = O_object, P.16 = P_object, P.17 = Q_object, P.18 = R_object, P.19 = S_object, P.20 = T_object, P.21 = U_object, P.22 = V_object, P.23 = W_object, P.24 = X_object, P.25 = Y_object, P.26 = Z_object, P. call_goal(Goal) :- write('AA001 Goal = ', Goal), Goal = [H | T], write('AA002 H = ', H, 'T = ', T), call_sub_1(H, T, 0). call_sub_1(H, T, N) :- write('BB001 H = ', H, 'T = ', T, 'N = ', N), T = [T1 | T2], H.N = T1, call_sub_1(H, T2, N + 1). call_sub_1(H, [], N) :- write('CC001 H = ', H), H. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% find_all from Prolog Programming in Depth %% by Michael A. Covington, Donald Nute, Andre Vellino %% page 164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% find_all(X, Goal, List) %% X contains one or more uninstantiated variables that can also occur in Goal. %% (X can be a single uninstantiated variable.) %% List is a list of all of the instantiations %% of X with which Goal will succeed. %% Modified (djd 2/2017) to remove explicit 'call' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% find_all(X, Goal, _) :- asserta(find_item('*MARK*')), Goal, asserta(find_item(X)), fail. find_all(_, _, List) :- find_collect([], L), !, List = L. find_collect(List1, List2) :- find_next(X), !, find_collect([X | List1], List2). find_collect(List, List). find_next(X) :- retract(find_item(X)), !, different(X, '*MARK*').