2.6. Strings

A string, both in Common-Lisp and in ECL is nothing but a vector of characters. Therefore, almost everything mentioned in the section of arrays remains valid here. The only important difference is that ECL stores strings as a lisp object with a pointer to a zero terminated C string. Thus, if a string has n characters, ECL will reserve n+1 bytes for the string. This allows us to pass the string self pointer to any C routine.

If x is a lisp object of type string, we can access the following fields:

x->string.dim

Maximum number of characters that it can contain.

x->string.fillp

Actual number of characters in the string.

x->string.self

Pointer to the characters.

x->string.hasfillp

True if x->string.fillp can be smaller than x->string.dim.

 Function: cl_object make_simple_string (char *s)
 Function: cl_object make_string_copy (char *s)

Both routines build a lisp string from a C string. make_string_copy allocates new space and copies the content of the string to it. make_simple_string simply uses the memory pointed by s, which should not be deallocated. Both routines use strlen to calculate the length of the string.