Quintus arg package

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2091 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2008-02-12 21:39:37 +00:00
parent 29d7bac9b7
commit 8ccc09d38f
1 changed files with 46 additions and 0 deletions

46
library/arg.yap Normal file
View File

@ -0,0 +1,46 @@
% This file has been included as an YAP library by Vitor Santos Costa, 2008
% it is based on the arg library from Quintus Prolog
:- module(arg,
[
genarg/3,
arg0/3,
genarg0/3,
args/3,
args0/3,
% project/3
path_arg/3
]).
arg0(0,T,A) :- !,
functor(T,A,_).
arg0(I,T,A) :-
arg(I,T,A).
genarg0(I,T,A) :-
nonvar(I), !,
arg0(I,T,A).
genarg0(0,T,A) :-
functor(T,A,_).
genarg0(I,T,A) :-
arg(I,T,A).
args(_,[],[]).
args(I,[T|List],[A|ArgList]) :-
genarg(I, T, A),
args(I, List, ArgList).
args0(_,[],[]).
args0(I,[T|List],[A|ArgList]) :-
genarg(I, T, A),
args0(I, List, ArgList).
project(Terms, Index, Args) :-
args0(Index, Terms, Args).
% no error checking here!
path_arg([], Term, Term).
path_arg([Index|Indices], Term, SubTerm) :-
genarg(Index, Term, Arg),
path_arg(Indices, Arg, SubTerm).