🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #791

Re: taking a predicate name as an argument

#791
From: Ken Johnson
Date: Sat, 14 Apr 1990 14:50
35 lines
1464 bytes
In article <2624D004.805@orion.oac.uci.edu> eaiu088@orion.oac.uci.edu
(Alisa Tannirat) writes:

% how do i take a predicate name as an argument and use it as a basis for
% selecting an operation on the other arguments?
% 
% for example, 
% 
% question(+, X, Y, Answer):-
%   Answer is X + Y.
% 
% question(*, X, Y, Answer):-
%   Answer is X * Y
% 
% i would like question to be general enough to take any operator and perform
% it on X and Y resulting in Answer.

question(Functor,Arg1,Arg2,Answer) :-
	functor(Term,Functor,2),
	arg(1,Term,Arg1),
	arg(2,Term,Arg2),
	Answer is Term.


% E mail bounces so often from here that I'm posting this anyway.
% Good luck. Email me directly and let me know if it worx.




-- 
Ken Johnson, AI Applications Institute, 80 South Bridge, Edinburgh EH1 1HN
E-mail ken@aiai.ed.ac.uk, phone 031-225 4464 extension 212
`I have read your article, Mr Johnson, and I am no wiser now than when I
started'.  -- `Possibly not, sir, but far better informed.'
Technical Details
Message-ID: <2225@skye.ed.ac.uk>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!edcastle!aiai!ken
References: <35047@brunix.UUCP> <2624D004.805@orion.oac.uci.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!edcastle!aiai!ken
From: ken@aiai.ed.ac.uk (Ken Johnson)
Newsgroups: comp.lang.prolog
Subject: Re: taking a predicate name as an argument
Message-ID: <2225@skye.ed.ac.uk>
Date: 14 Apr 90 14:50:30 GMT
References: <35047@brunix.UUCP> <2624D004.805@orion.oac.uci.edu>
Reply-To: ken@aiai.UUCP (Ken Johnson)
Followup-To: comp.lang.prolog
Organization: AIAI, University of Edinburgh, Scotland
Lines: 35