Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In Prolog it's very common to use single- or two-letter names for variables (which are all upper-case). The following is a typical example:

  member(X,[X|_Xs]).
  member(X,[_|Xs]):-
         member(X,Xs).
("|" is the cons operator in Prolog. An underscore means a don't-care variable).

In cases like this I think a "meaningful" variable name would actively hamper reading. For example:

  member(Element,[Element|_Rest_of_list]).
  member(Element,[_|Rest_of_list]) :-
         member(Element,Rest_of_list).
Personally, I stick to using a capital letter followed by an "s" for a list and the same capital letter alone for an element of a list, as above, though that is by no means a universal convention.

It's also common to use variables I,J,K,N,M for numbers and P,Q,R for predicate symbols (that can be passed as arguments to predicates, in Prolog). If the code sticks to the same convention throughout, it gets much easier to read than having to come up with special names for each variable ("Index", "Counter", "Next_value", "Length", etc).

And, if I remember correctly, the same kind of convention is common in Haskell, where I understand you can actualy "dash" variables (as in x, x').



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: