New Name
Stratego -- Strategies for Program Transformation
The
newname
strategy is a variant of the
new
strategy, which generates a new unique string. Newname generates unique strings, just like new, but it also accepts a prefix that will be part of the generated string. By default, the numbering is also done per prefix. For example, if you apply
newname
three times to the string
"foo"
, then the results will be
"foo_0"
,
"foo_1"
and
"foo_2"
. If
newname
is applied to
"bar"
after this, then the result will be
"bar_0"
, not
"bar_4"
. Thus, The
newname
strategy is very useful for generating more user-friendly, unique names in a program transformation.
The library strategy
newname
trims any trailing digits up to the rightmost '_'. Hence, repeated application of
newname
will not result in
mutiple numeric postfixes (for example
a_0_0
)
Example
<newname> "a" // produces "a_0"
; <newname> "b" // produces "b_0"
; <newname> "b_1" // produces "b_2"
; <newname> "b_1729" // produces "b_3"
; <newname> "b_a" // produces "b_a_0"