[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

I don't understand the documentation for string<=

Jim Newton

12/17/2015 2:41:00 PM

In sbcl string<= returns an integer.
However, this is what I see in the spec. http://clhs.lisp.se/Body/f_...


string<= string1 string2 &key start1 end1 start2 end2 => mismatch-index

string<=
string<= is true if substring1 is less than or equal to substring2; otherwise it is false.


What are substring1 and substring2? and in which case does string<= return true?
It seems to always return a number, thus it always returns true.

How is string< different than string<= ?

4 Answers

Jim Newton

12/17/2015 2:44:00 PM

0

With a little more experimentation, it seems that if the first string is NOT less than the second, string< does return nil, and when the < relation holds, it returns some integer. So it looks like it does indeed return true in this case.

Kaz Kylheku

12/17/2015 3:06:00 PM

0

On 2015-12-17, Jim Newton <jimka.issy@gmail.com> wrote:
> In sbcl string<= returns an integer.
> However, this is what I see in the spec.
> http://clhs.lisp.se/Body/f_...
>
>
> string<= string1 string2 &key start1 end1 start2 end2 => mismatch-index
>
> string<=
> string<= is true if substring1 is less than or equal to substring2;
> otherwise it is false.
>
>
> What are substring1 and substring2? and in which case does string<=
> return true?

I think the spec is referring to substrings because of the start and
end parameters. string1 and string2 themselves are compared only
by default; the general behavior is to operate on their substrings.

The following text is quite obviously flawed:

The inequality functions return a mismatch-index that is
true if the strings are not equal, or false otherwise. When
the mismatch-index is true, it is an integer representing the
first character position at which the two substrings differ,
as an offset from the beginning of string1.

Should say "... a mismatch-index that is true if the inequality is true ....".

Suggested replacement:

The inequality functions return a generalized boolean, which is a
mismatch index when true: the first character position at which
the two substrings differ, as an offset from the beginning of string1,
possibly one position beyond its last character.

> It seems to always return a number, thus it always returns true.
>
> How is string< different than string<= ?

(string< "A" "A") should return nil
(string<= "A" "A") should return 1: mismatch one position beyond length.

(string<= "Z" "A") should return nil: not the case on SBCL?

Assuming ASCII/Unicode/non-idiotic ordering of #\A and #\Z.

Pascal J. Bourguignon

12/17/2015 7:23:00 PM

0

Kaz Kylheku <kaz@kylheku.com> writes:

>> How is string< different than string<= ?
>
> (string< "A" "A") should return nil
> (string<= "A" "A") should return 1: mismatch one position beyond length.
>
> (string<= "Z" "A") should return nil: not the case on SBCL?
>
> Assuming ASCII/Unicode/non-idiotic ordering of #\A and #\Z.

You can assume, CL guarantees that (char< #\A #\Z).

http://www.lispworks.com/documentation/HyperSpec/Body...

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Marco Antoniotti

12/18/2015 8:46:00 AM

0

On Thursday, December 17, 2015 at 3:44:23 PM UTC+1, Jim Newton wrote:
> With a little more experimentation, it seems that if the first string is NOT less than the second, string< does return nil, and when the < relation holds, it returns some integer. So it looks like it does indeed return true in this case.

I haven't looked at the ANSI spec, but I'd bet that the result may be characterized as a "generalized boolean".

MA