next up previous
Next: The anonymous variable Up: Remarks on Variables Previous: Remarks on Variables

Naming variables

The only syntactic requirement that Prolog places on variables is that they start either with an upper case letter, or with an underscore. This means that you could restrict yourself to writing X, Y or Z when you want a variable. For example, the program first/2 in footnote 4 might look like this:
    first(X, Y):-
     X = [Z|W],
     Y = Z.
This will do exactly the same job as the original definition, but it is not a good idea Ð- as programs become more complex, they become very difficult to understand if you use such simple names for variables. Even this simple example illustrates how opaque such definitions can be come. By giving your variables mnemonic names, you help to document the function of your programs and to explain to a reader (including yourself) what information the variables are intended to convey.
Use mnemonic variables -- make your programs self-documenting.


Steve Harlow 2001-11-26