Hello,
I just found a bug in my program caused by thinking that
(array-dimension (format NIL "1234") 0) = 4.
Strange thing is that the answer is correct if I call string-downcase
on the value that format returns. I can understand why they behave so.
But are there some related rules on this matter? I checked Cltl I, but could
not find discussions on strlen in the string section. A quick solution that
I'm using now is to (1) scan the array, (2) coerce it to list then call
length, or (3) write a C function. Solution (1) doesn't seem safe, since
I cannot be sure that the strings will be padded with some fixed chars.
(2) is O(n), and (3) is not portable.
So, is there a portable O(1) STRLEN?
Thanks.
Wei Jen Yeh ···@cs.purdue.edu
Department of Computer Science
Purdue University
West Lafayette, Indiana
In article <·····@ector.cs.purdue.edu>, I wrote...
> Hello,
> I just found a bug in my program caused by thinking that
> (array-dimension (format NIL "1234") 0) = 4.
> ...
>
> So, is there a portable O(1) STRLEN?
>
Thanks. I found the answer --- LENGTH.
Wei Jen Yeh ···@cs.purdue.edu
Department of Computer Science
Purdue University
West Lafayette, Indiana
In article <·····@ector.cs.purdue.edu> ···@cs.purdue.EDU (Wei Jen Yeh) writes:
>Hello,
> I just found a bug in my program caused by thinking that
> (array-dimension (format NIL "1234") 0) = 4.
Is FORMAT returning a longer string with a fill pointer? I thought that
functions that create strings were supposed to return simple strings. What
Lisp does this?
>So, is there a portable O(1) STRLEN?
LENGTH is O(1) when the argument is a vector, although the coefficient will
usually be higher than ARRAY-DIMENSION, since it has to check whether the
argument is a vector or list, and whether it has a fill pointer.
--
Barry Margolin
System Manager, Thinking Machines Corp.
······@think.com {uunet,harvard}!think!barmar