We can add an extra argument which can be used to return a result.
sentence([[np,NP],[vp,VP]])What we have done above is declare predicates sentence/3, noun_phrase/3, verb_phrase/3, determiner/3 and so on. The explicit argument is the first and the two others are added when the clause is read in by Prolog. Basically, Prolog expands a grammar rule with n arguments into a corresponding clause with n+2 arguments.
and so on
So what structure is returned from solving the goal:
sentence(Structure,[the,man,ate,a,cake],) [-5pt]The result is:
[[np,[[det,the],[noun,man]]],[vp,[... [-5pt]Not too easy to read!
We can improve on this representation if we are allowed to use Prolog terms as arguments. For example, in foo(happy(fred),12) the term happy(fred) is one of the arguments of foo/2. Such a term is known as a compound term. We discuss this at greater length in chapter 10.
With the help of compound terms, we could tidy up our representation of sentence structure to something akin to:sentence([np([det(the),noun(man)]),vp([... [-5pt]