Re: Name For - Functions that indicate order?



Stone Free <spam_KillKillKillstone_freeNoSpamPleaseWereBritish@xxxxxxxxxxx> writes:

Hi,

I am writing the documentation for some of my code, and I want to name one
of my functions more correctly.

I have written a predicate that returns true if the left hand object comes
earlier in a sequence and false if not.

At the moment the function is called CompareItem, I am trying to come up
with a better name and a better description

It is used in two situations:

First as an argument to a sorting function, and so I could write
"Desc: Predicate used to sort entire vector". Of course it does
not actually sort anything it only indicates that the left hand
object does or does not come before the right hand object in the
sequence.

Secondly it is used as an argument to equal_range (C++ STL), and so
it is used to search for an item. and so I could write "Desc:
Predicate used to search for an item in a vector". Again the
function doesn't actually do the searching, and whilst it does do a
comparison, I want the name to imply that the function dictates the
ordering of the two items passed to it as arguments.

Or I could leave it at as:

Func: CompareItem
Desc: Compares two items and returns true if the left hand object comes
earlier in the sequence and false if not.
bool CompareItem(Item lhs,Item rhs);

Can anyone come up with a better name for the function, and better notes
for the documentation of the function?

The sequence defines an order, and this function IS the order relationship.

Recently I had to sort elements by some tags, given a tag order. So
obviously, I named the function TAG-ORDER.

(let ((tag-order (make-order-from-tags '(big middle small tiny))))
(sort items tag-order :key (function item-tag)))


--
__Pascal Bourguignon__ http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.
.



Relevant Pages

  • Re: Am I abusing SORT? It sure aint working for me....
    ... If the key and predicate always return, ... producing a sequence containing the same ... sequence will respect that partial order --- in other words, ... can use sort to do topological sort. ...
    (comp.lang.lisp)
  • Re: Go Fish game in Lisp
    ... >> I have a function for shuffling a list into random order. ... However SORT *is* guaranteed to terminate as long as the predicate ... producing a sequence containing the same ...
    (comp.lang.lisp)
  • Re: How Best to Randomize a List?
    ... It wouldn't work with bubble sort -- ... the poor thing would terminate only by accident. ... predicate is consistent, that makes them do what we want given this ... result of sorting a sequence by a random predicate will produce all ...
    (comp.lang.lisp)
  • Re: Am I abusing SORT? It sure aint working for me....
    ... sequence will respect that partial order --- in other words, ... can use sort to do topological sort. ... if the predicate I give is a partial ...
    (comp.lang.lisp)
  • Re: how to test for nil input in a recursive function?
    ... satisfies a given predicate will return true for empty sequences since ... EVERY returns true iff Px. ... of a sequence, only about a particular one, if it exists. ...
    (comp.lang.lisp)