Article View: comp.lang.prolog
Article #792Re: taking a predicate name as an argument
From: David Bowen
Date: Sun, 15 Apr 1990 01:05
Date: Sun, 15 Apr 1990 01:05
27 lines
1571 bytes
1571 bytes
In article <28908@cup.portal.com> pgl@cup.portal.com (Peter G Ludemann) writes:
>- Functor names can't be variables. It would seem that this
> could be overcome by using =../2:
>
> question(Pred, X, Y, Answer) :-
> F =.. [Pred, X, Y],
> Answer is F .
>
>- But general terms aren't allowed with "is" (at least, this is
> the case with Quintus 2.x; I assume it's true of others); if
> you try this, you will get a run-time error for is/2.
>
>So, the answer would seem to be "it can't be done" in many
>popular Prologs; you'll just have to list out all the arithmetic
>operators yourself (there aren't too many, fortunately).
It can be done, like this:
question(Pred, X, Y, Answer) :-
F =.. [Pred, X, Y],
call(Answer is F).
In future releases of Quintus Prolog it won't be necessary to put in the
call/1 wrapper.
If efficiency is of any concern, though, it would be better to have a
clause for each arithmetic operator as Peter suggested.
Technical Details
Message-ID:
<1353@quintus.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!zaphod.mps.ohio-state.edu!uwm.edu!bionet!arisia!quintus!daveReferences:
<35047@brunix.UUCP> <2624D004.805@orion.oac.uci.edu> <28908@cup.portal.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!zaphod.mps.ohio-state.edu!uwm.edu!bionet!arisia!quintus!dave From: dave@quintus.UUCP (David Bowen) Newsgroups: comp.lang.prolog Subject: Re: taking a predicate name as an argument Message-ID: <1353@quintus.UUCP> Date: 15 Apr 90 01:05:01 GMT References: <35047@brunix.UUCP> <2624D004.805@orion.oac.uci.edu> <28908@cup.portal.com> Reply-To: dave@quintus.UUCP (David Bowen) Organization: Quintus Computer Systems, Inc. Lines: 27