% The CSIRO Software License, Version 1.0 % (based on the Apache Software License Version 1.1) % % % Copyright (c) 2001 Commonwealth Scientific and Industrial % Research Organisation (CSIRO). All rights % reserved. % % Redistribution and use in source and binary forms, with or without % modification, are permitted provided that the following conditions % are met: % % 1. Redistributions of source code must retain the above copyright % notice, this list of conditions and the following disclaimer. % % 2. Redistributions in binary form must reproduce the above copyright % notice, this list of conditions and the following disclaimer in % the documentation and/or other materials provided with the % distribution. % % 3. The end-user documentation included with the redistribution, % if any, must include the following acknowledgment: % "This product includes software developed by % CSIRO (http://www.cmis.csiro.au/)." % Alternately, this acknowledgment may appear in the software itself, % if and wherever such third-party acknowledgments normally appear. % % 4. The name "CSIRO" must % not be used to endorse or promote products derived from this % software without prior written permission. For written % permission, please contact address@hidden % % 5. Products derived from this software may not be called "CSIRO", % nor may "CSIRO" appear in their name, without prior written % permission of CSIRO. % % THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED % WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES % OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE % DISCLAIMED. IN NO EVENT SHALL CSIRO OR % ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, % SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT % LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF % USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND % ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, % OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT % OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF % SUCH DAMAGE. lr_lambda(G, G2, Atom) :- G = :-(H, B), H =.. [lambda|Args], new_atom(Atom), H2 =.. [Atom|Args], G2 = :-(H2, B). lambda_curry(Lambda, Args, Goal) :- ( Lambda = :-(_,_) -> tr_lambda(Lambda, L2, Atom), asserta(L2), curry(Atom, Args, Goal) ; curry(Lambda, Args, Goal) ). % right curry Goal with AddArgs to create CurriedGoal rcurry(Goal, AddArgs, CurriedGoal) :- Goal =.. GoalArgs, append([F], Args, GoalArgs), append(AddArgs, Args, CurriedArgs), CurriedGoal =.. [F|CurriedArgs]. % curry Goal with AddArgs to create CurriedGoal curry(Goal, AddArgs, CurriedGoal) :- Goal =.. GoalArgs, append(GoalArgs, AddArgs, CurriedArgs), CurriedGoal =.. CurriedArgs. % Map predicates use curry/3 to add arguments to functor given. % Map a functor F with arity 3 over given lists. map(F, [X|Xs], [Y|Ys], [Z|Zs], [U|Us]) :- !, curry(F, [X, Y, Z, U], Goal), Goal, map(F, Xs, Ys, Zs, Us). map(_, [], [], [], []) :- !. % Map a functor F with arity 3 over given lists. map(F, [X|Xs], [Y|Ys], [Z|Zs]) :- !, curry(F, [X, Y, Z], Goal), Goal, map(F, Xs, Ys, Zs). map(_, [], [], []) :- !. % Map a functor F with arity 2 over given lists. map(F, [X|Xs], [Y|Ys]) :- !, curry(F, [X, Y], Goal), Goal, map(F, Xs, Ys). map(_, [], []) :- !. % Map a functor F with arity 1 over given list. map(F, [X|Xs]) :- !, curry(F, [X], Goal), Goal, map(F, Xs). map(_, []) :- !. % Helper for using keysort. make_pair(A,B, A-B).