GenerateIdentifier - Maple Help

StringTools

 GenerateIdentifier
 create an identifier sequence generator

 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

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{gen}≔\mathrm{GenerateIdentifier}\left(\right):$
 > $\mathrm{gen}\left(\right),\mathrm{gen}\left(\right),\mathrm{gen}\left(\right)$
 ${"t"}{,}{"t0"}{,}{"t1"}$ (1)
 > $\mathrm{gen}≔\mathrm{GenerateIdentifier}\left('\mathrm{maxlen}'=2\right):$
 > $\mathrm{seq}\left(\mathrm{gen}\left(\right),i=1..10\right):$
 > $\mathrm{gen}\left(\right)$
 ${"t9"}$ (2)
 > $\mathrm{GenerateIdentifier}\left('\mathrm{base}'="foobar",'\mathrm{maxlen}'=2\right):$
 > $\mathrm{gen}≔\mathrm{GenerateIdentifier}\left('\mathrm{usename}'="int",'\mathrm{maxlen}'=3\right):$
 > $\mathrm{gen}\left(\right),\mathrm{gen}\left(\right),\mathrm{gen}\left(\right),\mathrm{gen}\left(\right)$
 ${"int"}{,}{"in0"}{,}{"in1"}{,}{"in2"}$ (3)
 > $\mathrm{seq}\left(\mathrm{gen}\left(\right),i=5..111\right)\left[-20..-1\right]$
 ${"i80"}{,}{"i81"}{,}{"i82"}{,}{"i83"}{,}{"i84"}{,}{"i85"}{,}{"i86"}{,}{"i87"}{,}{"i88"}{,}{"i89"}{,}{"i90"}{,}{"i91"}{,}{"i92"}{,}{"i93"}{,}{"i94"}{,}{"i95"}{,}{"i96"}{,}{"i97"}{,}{"i98"}{,}{"i99"}$ (4)
 > $\mathrm{gen}\left(\right)$
 > $\mathrm{gen}≔\mathrm{GenerateIdentifier}\left('\mathrm{usename}'="rational"\right):$
 > $\mathrm{gen}\left(\right),\mathrm{gen}\left(\right),\mathrm{gen}\left(\right)$
 ${"ration"}{,}{"ratio0"}{,}{"ratio1"}$ (5)
 > $\mathrm{seq}\left(\mathrm{gen}\left(\right),i=4..111110\right):$
 > $\mathrm{gen}\left(\right)$
 ${"r99999"}$ (6)
 > $\mathrm{gen}\left(\right)$
 > $\mathrm{gen}≔\mathrm{GenerateIdentifier}\left('\mathrm{usename}'='\mathrm{alphabet}'\right):$
 > $\mathrm{gen}\left(\right),\mathrm{gen}\left(\right),\mathrm{gen}\left(\right)$
 ${"a"}{,}{"b"}{,}{"c"}$ (7)
 > $\mathrm{seq}\left(\mathrm{gen}\left(\right),i=1..300\right):$
 > $\mathrm{gen}\left(\right),\mathrm{gen}\left(\right),\mathrm{gen}\left(\right)$
 ${"kr"}{,}{"ks"}{,}{"kt"}$ (8)

Compatibility

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