General
Material
Lecture 1
Lecture 2
Lecture 3
Lecture 4
Lecture 5

Hint

First, don't worry about the identation. Try to produce an output that looks as follows:

s(
np(
det(the)
n(nurse))
vp(
vi(whistles)))
    

To do that, you have to work your way recursively through the complex term. While your input term is complex you get the functor of the complex term and print it to a new line. Then you print one by one all arguments of the complex term. For this, you have to write a recursive predicate which goes through the list of arguments.

If your input term is an atom, you just print the atom.

Solution

Back to the exercise.