MCENANEY WILLIAM J wrote:
> Thanks for that good idea. I could write a C function for a small job.
> Or I could do the job in Perl or in Basic. But I'm talking about
> language design, not about how I might solve a particular minor problem.
>
> Although I have been failing to make my ideas clear to everybody, I
> believe firmly in saying what I mean. That's partly why I dislike
> "if (strcmp (s1, s2) == 0) . . ." Suppose I happen to forget what strcmp()
> is saying when it returns a zero. Then I'll have to find out what it's
> telling me. But if I make my meaning plain with one operator, I wipe
> out a function call, and I avoid reading a man page.
>
> If the compiler wants to generate a call to strcmp(), that's all right
> with me. But it seems to me that programming languages are designed
> for people, not for computers.
Basic was designed for people. C was effectively designed for the
computer; it was intended as a portable replacement for assembly
language.
The issue isn't specific to C, either. It's a general of how you
choose to define equality. And there can be multiple valid
definitions. In a language which supports explicit references (e.g.
pointers), it's meaningful to define equality on references as either
a) whether the references refer to the same object, or
b) whether the objects that they refer to are `equal'.
There are plenty of other ways in which multiple definitions are
meaningful. In the example being discussed, strcmp() could
meaningfully be replaced by strcasecmp(), if you consider case
distinctions to be irrelevant.
Or consider the case where the strings represent filenames. It would
be useful if `foo' and `subdir/../foo' were considered equal.
Lisp has three `standard' equality functions: eq, eql and equal, plus
various others (e.g. `=' applies only to numbers). Haskell has a
standard class `Eq', for types which posess an equality predicate.
It's not uncommon for functions in `template' classes (e.g. sets,
hashtables) to accept a pointer to an equality function, so you can
choose what sort of equality you want.
--
Glynn Clements <[EMAIL PROTECTED]>