Skip to main content

simple-string-p

simple-string-p Function

Syntax:

simple-string-p object → generalized-boolean

Arguments and Values:

object—an object.

generalized-boolean—a generalized boolean.

Description:

Returns true if object is of type simple-string; otherwise, returns false.

Examples:

(simple-string-p "aaaaaa") → true 
(simple-string-p (make-array 6
:element-type ’character
:fill-pointer t)) → false


Notes:

(simple-string-p object) (typep object ’simple-string)

Expanded Reference: simple-string-p

Testing string literals

String literals are simple strings -- they have no fill pointer and are not displaced or adjustable.

(simple-string-p "hello")
=> T

(simple-string-p "")
=> T

Strings from make-string are simple

make-string always produces simple strings.

(simple-string-p (make-string 10 :initial-element #\x))
=> T

Strings with fill pointers are not simple

A string created with a fill pointer is not a simple string.

(simple-string-p
(make-array 6 :element-type 'character
:fill-pointer t
:initial-element #\a))
=> NIL

Adjustable strings are not simple

Adjustable arrays (including adjustable strings) are not simple strings.

(simple-string-p
(make-array 5 :element-type 'character
:adjustable t
:initial-element #\z))
=> NIL

Non-string objects return NIL

simple-string-p returns NIL for any object that is not a simple string.

(simple-string-p #\a)
=> NIL

(simple-string-p 42)
=> NIL

(simple-string-p '(h e l l o))
=> NIL

(simple-string-p #(#\h #\e #\l #\l #\o))
=> NIL

Equivalence with typep

(simple-string-p x) is equivalent to (typep x 'simple-string).

(let ((s "test"))
(eql (simple-string-p s) (typep s 'simple-string)))
=> T