Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!psuvax1!psuvm!awiwuw11!neumann From: NEUMANN@awiwuw11.wu-wien.ac.at (Gustaf Neumann) Newsgroups: comp.lang.prolog Subject: Re: Meta-programming question Message-ID: <90242.131546NEUMANN@awiwuw11.wu-wien.ac.at> Date: 30 Aug 90 12:57:02 GMT Organization: Wirtschaftsuniversitaet Wien, Vienna, Austria Lines: 43 > I'm working on a meta-programming project and have run across something > I just can't figure a way to do. I want to locate a clause via > unification with its head, and then be able to retrieve the clause > *without binding any variables*. The goal here is to modify the clause > and replace it, so it's essential that I avoid making unintended > changes via bindings. I am not sure wether the following Prolog-clause is exactly what you want, but maybe you can use it as a first approximation: %get_clause(+,-,-) get_clause(Match,Head,Body) :- functor(Match,F,A), functor(Head,F,A), clause(Head,Body), \+ \+ Head=Match. ?- get_clause(member(a,[X|Y]),Head,Body). Body = true, Head = member(_199,[_199|_202]), X = _65, Y = _79 ? ; Body = member(_199,_202), Head = member(_199,[_201|_202]), X = _65, Y = _79 ? If this version is not fast enough for your application, one should think about a more clever representation of the clauses. -gustaf ------------------------------------------------------------------- Gustaf Neumann neumann@dec4.wu-wien.ac.at, neumann@awiwuw11.bitnet Vienna University of Economics and Business Administration Augasse 2-6, A-1090 Vienna, Austria Tel: +43 (222) 347-541 x533 Fax 347-555