%% Copyright (C) 2017 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(1, A, nop, nop) :- A :\== nop. check_arity(2, A, B, nop) :- A :\== nop, B :\== nop. check_arity(3, A, B, C) :- A :\== nop, B :\== nop, C :\== 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) :- P = Relation, P.1 = Logical_Form, P.2 = A_object, P.3 = B_object, P.4 = C_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*').