StringTools
GenerateIdentifier
create an identifier sequence generator
Calling Sequence
Parameters
Description
Examples
Compatibility
GenerateIdentifier( opts )
opts
-
(optional) options
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.
with⁡StringTools:
gen≔GenerateIdentifier⁡:
gen⁡,gen⁡,gen⁡
t,t0,t1
gen≔GenerateIdentifier⁡maxlen=2:
seq⁡gen⁡,i=1..10:
gen⁡
t9
GenerateIdentifier⁡base=foobar,maxlen=2:
Error, (in StringTools:-GenerateIdentifier) base for identifiers is too long
gen≔GenerateIdentifier⁡usename=int,maxlen=3:
gen⁡,gen⁡,gen⁡,gen⁡
int,in0,in1,in2
seq⁡gen⁡,i=5..111−20..−1
i80,i81,i82,i83,i84,i85,i86,i87,i88,i89,i90,i91,i92,i93,i94,i95,i96,i97,i98,i99
Error, (in gen) no more identifiers
gen≔GenerateIdentifier⁡usename=rational:
ration,ratio0,ratio1
seq⁡gen⁡,i=4..111110:
r99999
gen≔GenerateIdentifier⁡usename=alphabet:
a,b,c
seq⁡gen⁡,i=1..300:
kr,ks,kt
The StringTools[GenerateIdentifier] command was updated in Maple 2017.
The usename option was updated in Maple 2017.
See Also
string
Download Help Document