Discussion:
string-equal/equalp
(too old to reply)
Andreas Thiele
2005-08-16 10:31:23 UTC
Permalink
Hi,

I can use string-equalp or equalp if I'm not interested in case when comparing strings. Is there an
advantage of using string-equal? Which one should be preferred? Just a question of style?

Andreas
Edi Weitz
2005-08-16 11:13:19 UTC
Permalink
Post by Andreas Thiele
I can use string-equalp or equalp if I'm not interested in case when
comparing strings. Is there an advantage of using string-equal?
Which one should be preferred? Just a question of style?
I would assume that on most implementations STRING-EQUAL is a bit
faster (given the right optimization declarations) because it "knows"
that its arguments are strings. It's most likely a micro-optimization
that's only noticable in tight loops.

It can also be self-documenting to use STRING-EQUAL because the reader
of your code then knows that you expect both of its arguments to be
strings.

HTH,
Edi.
--
Lisp is not dead, it just smells funny.

Real email: (replace (subseq "***@agharta.de" 5) "edi")
Andreas Thiele
2005-08-16 14:25:17 UTC
Permalink
TNX
Kent M Pitman
2005-08-17 15:36:19 UTC
Permalink
Post by Edi Weitz
I would assume that on most implementations STRING-EQUAL is a bit
faster (given the right optimization declarations) because it "knows"
that its arguments are strings.
"string designators"

People who don't know about designators in general should definitely read

http://www.lispworks.com/documentation/HyperSpec/Body/01_dae.htm

It's an important concept no one should be unaware of when reading the spec.

String designators are defined here:

http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_s.htm#string_designator
Wade Humeniuk
2005-08-16 15:32:28 UTC
Permalink
Post by Andreas Thiele
Hi,
I can use string-equalp or equalp if I'm not interested in case when comparing strings. Is there an
advantage of using string-equal? Which one should be preferred? Just a question of style?
Andreas
Just look at the definition (from the CLHS) at the two function
definitions,

equalp x y => generalized-boolean
string-equal string1 string2 &key start1 end1 start2 end2 => generalized boolean

STRING-EQUAL allows bounding indexes on the string (since it is a sequence)

If one needs to compare a substring of a string you would need to use
subseq (or such) to effectively use EQUALP, STRING-EQUAL would be
more efficient.

Wade
Andreas Thiele
2005-08-17 08:29:11 UTC
Permalink
Thanks for your hints Wade & Edi,

I just noticed my own 'bad habit' of using equalp whenever I needed non case sensitive string
comparison. When reading your hints, they seem obvious to me.

Habit abadoned!

:)

Andreas
Loading...