🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #1136

Re: Meta-programming question

#1136
From: Gustaf Neumann
Date: Thu, 30 Aug 1990 12:57
43 lines
1753 bytes
> 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
Technical Details
Message-ID: <90242.131546NEUMANN@awiwuw11.wu-wien.ac.at>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!psuvax1!psuvm!awiwuw11!neumann

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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