True, but there is an efficiency issue.
If you do the test in the head, then Prolog can do some clever things, e.g.:
pred([], ...) :- ...
pred([X|Xs], ...) :- ...
allows the Prolog compiler to generate “indexing” code that so that at runtime it can go directly to the appropriate clause without creating any choice points.
If instead you have
pred([], ...) :- ...
pred(L, ...) :- L = [X|Xs], ...
then the indexing code isn’t generated, so extra choice points are left around.
An unnecessary choice point not only slows things down (by allowing unnecessary backtracking), but also can cause some values to go onto the heap rather than the stack. Adding a “cut” (e.g., pred(X, ...) :- L = [X|Xs], !, ... only partially improves the situation – it’s best to have enough information in the head of the clause to avoid the creation of a choicepoint in the first place.
If you do something like this:
pred([X|Xs], ...) :- ... pred2([X|Xs]), ...
there is a slight inefficiency in creating the 2nd list from [X|Xs] but it’s much less overhead than the gain from the indexing code – [X|Xs] can be as little as a one or two byte code instructions, and can create a cell on the stack, which is automatically removed by tail recursion optimization.
[In theory, a Prolog compiler could detect that the creation of [X|Xs] uses a value from the head, but I’m not aware of any compiler that does this – if you want to know more about the kinds of local and global optimizations that are possible, see Peter van Roy’s thesis on the Aquarius compiler and SWI Prolog deep indexing.]
The bottom line is: put as much structure as you can into the head of a clause and don’t worry about “duplicate” creation of terms.