Path: 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 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.'