properName(X)
is just an unary rule (in the context of DCG; it is a ternary predicate in Prolog - check it out with ?- listing(properName)
). you could've called it "socks", or "jam", it's totally up to you. So the semantic knowledge about it representing proper name "john" or "mary" is nowhere to be found in the code (it uses naming as self-documenting feature, but documentation is not code).
The predicate allows for an atom john
or mary
to be present in the input stream, and nothing else; and demands that X
unified with that atom.
You could've defined it thus:
name(X) --> [X], { member(X, [john, mary]) }.
then,
4 ?- phrase( name(X), [john,jack], Z).
X = john,
Z = [jack] ;
false.
5 ?- phrase( name(X), [jack,john], Z).
false.
8 ?- phrase( name(X), [john,mary], Z).
X = john,
Z = [mary] ;
false.
9 ?- phrase( name(X), [mary,john,jack], Z).
X = mary,
Z = [john, jack].
11 ?- phrase( name(jack), [jack,mary,john], Z).
false.