GenerateIdentifier - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


StringTools

  

GenerateIdentifier

  

create an identifier sequence generator

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

GenerateIdentifier( opts )

Parameters

opts

-

(optional) options

Description

• 

The GenerateIdentifier command returns a procedure that, when invoked repeatedly, returns strings for use as identifiers.

• 

Identifiers are, by default, formed by using the string t as a base, and appending integer suffices until the length of the resulting string exceeds a specified maximum length.

• 

The default maximum length is 6.

• 

The maximum length can be changed by specifying the maxlen = LEN option, which takes a positive integer value LEN.

• 

The default base string t can be changed by specifying the base = STRING option. In this case, the value of STRING will be used instead of t.

• 

The value of the base string must not exceed the maximum identifier length.

• 

An alternative system of generating names can be invoked by using the usename = STRING option. In this form, the returned generator forms strings by using maximal prefixes of the given string, replacing suffixes up to the maximum identifier length with digit sequences on subsequent calls.

• 

The maximal prefix of the STRING used is shortened as long as at least one character from the string remains.

• 

When no more unique strings not exceeding the maximum length can be generated, the returned generator raises the exception "no more identifiers".

• 

A third option for generating identifiers can be invoked by using the usename = alphabet option. In this case, identifiers of the form a, b, ..., z, aa, ab, etc., are generated, up to the maximum identifier length.

• 

All of the StringTools package commands treat strings as (null-terminated) sequences of 8-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

withStringTools:

genGenerateIdentifier:

gen,gen,gen

t,t0,t1

(1)

genGenerateIdentifiermaxlen=2:

seqgen,i=1..10:

gen

t9

(2)

GenerateIdentifierbase=foobar,maxlen=2:

Error, (in StringTools:-GenerateIdentifier) base for identifiers is too long

genGenerateIdentifierusename=int,maxlen=3:

gen,gen,gen,gen

int,in0,in1,in2

(3)

seqgen,i=5..11120..1

i80,i81,i82,i83,i84,i85,i86,i87,i88,i89,i90,i91,i92,i93,i94,i95,i96,i97,i98,i99

(4)

gen

Error, (in gen) no more identifiers

genGenerateIdentifierusename=rational:

gen,gen,gen

ration,ratio0,ratio1

(5)

seqgen,i=4..111110:

gen

r99999

(6)

gen

Error, (in gen) no more identifiers

genGenerateIdentifierusename=alphabet:

gen,gen,gen

a,b,c

(7)

seqgen,i=1..300:

gen,gen,gen

kr,ks,kt

(8)

Compatibility

• 

The StringTools[GenerateIdentifier] command was updated in Maple 2017.

• 

The usename option was updated in Maple 2017.

See Also

string

StringTools