Ken Tilton <kentilton@gmail.com> wrote:
+---------------
| (position #\a "bbaa" :start 42) -> 76?
|
| puh-lease.
|
| Actually, I am whining about CLHS, doesn't say word about
| oddball values for start.
+---------------
Well, actually, it sort of does, in that:
Function POSITION, POSITION-IF, POSITION-IF-NOT
...
Arguments and Values:
...
start, end---bounding index designators of sequence.
The defaults for start and end are 0 and nil, respectively.
And then if you go to the glossary entries for (all three of!)
BOUNDING INDEX DESIGNATOR, BOUNDING INDEX, and BOUNDED, you
eventually get to this bit:
...restricted to a subrange of the elements of S that...
and 42 is certainly *NOT* a designator for a :START that's restricted
to a subrange of "bbaa". So 42 is not a proper type for a :START arg
in this case.
And CLHS 1.4.4.3 "The ``Arguments and Values'' Section of a Dictionary
Entry" very clearly states:
Except as explicitly specified otherwise, the consequences
are undefined if these type restrictions are violated.
And we all know about the CLHS and undefined behaviors... ;-} ;-}
-Rob
p.s. Of course, any *decent* implementation will be more gentle,
and instead of starting WW3 or emitting snot monkeys will throw you
a handleable type error, e.g., CMUCL:
> (multiple-value-list (ignore-errors (position #\a "bbaa" :start 42)))
(NIL #<TYPE-ERROR {48970025}>)
> (format t "~a~%" (second *))
Type-error in KERNEL::INVALID-ARRAY-INDEX-ERROR-HANDLER:
42 is not of type (INTEGER 0 (4))
NIL
>
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607