tiny prolog problem

Martin Jansche jansche at ling.ohio-state.edu
Sat Feb 24 18:59:13 UTC 2001


Dear Anonymous,

On Sat, 24 Feb 2001, xs wrote:

> Please help me with my non-HPSG-related homework problem.
>
> I have to do a "selective" listing of all obj which have a given
> value as first term
[...]
> I have to use "FAIL" cause I want ALL the obj with that number to
> be listed... without that fail onnly the first occurrence will be
> listed...
>
> obj(1,der,dse).
> obj(1,dasdsasd,mn).
> obj(1,rewrew,f).
> obj(2,fre,fr).
>
[...]
> listit(Num):-obj(Num,A,_),write(A),fail.

You might want to get a basic Prolog textbook and read up on
failure-driven loops, and declarative vs. procedural readings of
programs.

Remember that Prolog uses implicit quantification and that P -> Q is
equivalent to ~(P & ~Q).  Then you can write:

  listit(Num) :- \+ ( obj(Num,A,_), \+ write(A)).

Good luck,

- martin



More information about the HPSG-L mailing list