Check for one-element list in Prolog
<p>I'm very new to Prolog (coming from C++) and am having trouble understanding using lists as parameters. In particular, I am wondering how to account for the case in which a list only has one element (the tail is "empty"). Why can't I have [L] as a parameter by itself? Why must a tail be explicitly included?</p>

<pre><code>/** Trying to print out the head of the list */
writeList([L|_]) :- write(L).      /** Works fine */
writeList([L]) :- write(L).        /** Doesn't work. Will return false, but why? */
writeList([L]) :- write([L]).      /** I thought I'd try this to see if it was a 
                                   problem with write(), but this returns false as well. */
</code></pre>

<p>The only way solution I came up with (without creating tests after the ":-") was:</p>

<pre><code>writeList([L|[]]) :- write(L).
</code></pre>

<p>But it seems a bit messy to have to specify the tail is [].  Is there any cleaner way to do this?</p>

<p>Sorry if this question is very silly--I've tried to find an answer to this (quite basic) question but I suspect there's a problem in my fundamental understanding here.</p>