Generic FunctionPackage: exclToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.0
Unrevised from 9.0 to 10.0.
9.0 version

prefixp

Arguments: prefix sequence

The default methods for all types of sequences do the following: prefix and sequence must be sequences.

This function returns a non-nil value if sequence starts with prefix and returns nil otherwise. nil is always returned if prefix is longer than sequence.

The value returned when sequence does start with prefix is the length of prefix. If prefix is shorter than sequence, this value is also the index of the element just after the prefix portion of sequence.

Examples

(prefixp "foo" "foobar") => 3 ;; The length of "foo" and the
                                 ;; index of #\b in "foobar"
(prefixp "foo" "foo") => 3 ;; the length of "foo"
(prefixp "foo1" "foo2") => nil
(prefixp "foo1" "foo") => nil
(prefixp '(1 2 3) '(1 2 3 4 5 6 7)) => 3
(prefixp (list #\f) "foo")  => 1
(prefixp "f" (vector \#f #\o)) => 1

;; Some arguments always return the same value.
;; So if PREFIX-USED has length 0, 0 is returned:
(prefixp "" [any-sequence]) -> 0
(prefixp nil [any-sequence]) -> 0

;; USE CASE: Suppose the value of a variable is a string made up 
;; of an OS name followed by a version number. Then if PREFIX
;; is a particular OS name, we can test for whether the OS 
;; named in the variable is an instance of that OS:

(defvar *os-version* "CENTOS-4.5.21")
(defun centos-p (str) (prefixp "CENTOS" str))
(centos-p *os-version*) -> 6 ;; that is true
(setq *os-version* "REDHAT-4.5.21")
(centos-p *os-version*) -> nil

Copyright (c) 1998-2019, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 9.0 page.
Created 2015.5.21.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.0
Unrevised from 9.0 to 10.0.
9.0 version