Generic FunctionPackage: exclToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
The object described on this page has been modified in the 10.1 release; see the Release Notes.
10.0 version

prefixp

Arguments: prefix sequence &optional prefix-length

The default methods for all types of sequences do the following: prefix and sequence must be sequences. prefix-length must be nil or a fixnum less than or equal to the length or prefix. In what follows, prefix-used is prefix if prefix-length is nil and (subseq prefix 0 prefix-length) if prefix-length is a fixnum.

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

The value returned when sequence does start with prefix-used is the length of prefix-used. If prefix-used is shorter than sequence, this value is also the index of the element just after the prefix-used 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
(prefixp [any-sequence] [any-sequence] 0) -> 0

;; Examples with prefix-length non-nil:
(prefixp "foo" "foo2" 3) -> 3
(prefixp "foo1" "foo2" 3) -> 3
(prefixp "foo12345" "foo2" 3) -> 3
(prefixp "foo12345" "foo2" 4) -> nil

;; 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-2017, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 10.0 page.
Created 2017.2.15.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
The object described on this page has been modified in the 10.1 release; see the Release Notes.
10.0 version