vl-string-search issue

vl-string-search issue

john.uhden
Mentor Mentor
985 Views
2 Replies
Message 1 of 3

vl-string-search issue

john.uhden
Mentor
Mentor

With strings I think that counting from zero (0) is a bad idea...

(vl-string-search "" "ABCDE") returns 0.

That's okay with me, but

(vl-string-search "A" "ABCDE") also returns 0.

which leaves me a lot more work on the function I was writing.  😕

John F. Uhden

0 Likes
Accepted solutions (1)
986 Views
2 Replies
Replies (2)
Message 2 of 3

martti.halminen
Collaborator
Collaborator
Accepted solution

This is an instance of one of the eternal fights in programming language design: should array indexing start at 0 or 1?

https://en.wikipedia.org/wiki/Zero-based_numbering

 

Some languages like Fortran and Pascal use 1, others like C and its relatives use 0.

 

Many of the VL- functions are copied from corresponding Common Lisp functions, which uses zero-based indexing.

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

 

- which is actually inconsistent with older parts of AutoLISP, for example SUBSTR uses 1-based indexing.

 

At this stage changing this is impossible, there are tens of thousands of customers using the current version, changing that would break their software.

- On the other hand, the reason there is a Unix command named "creat" instead of "create" was "we can't change that any more, we already have six users".

 

The other part of the problem, what happens with "", probably goes back to mathematical thinking: in set theory an empty set is a subset of every set.

 

-- 

 

 

 

 

 

 

0 Likes
Message 3 of 3

john.uhden
Mentor
Mentor

Thank you, @martti.halminen 

Your explanation is well put and leaves us with the reality that we just have to deal with it.  😞

John F. Uhden

0 Likes