From 256083dd188ad69c034211d5feecba3bf46ce0b9 Mon Sep 17 00:00:00 2001 From: Bourgerie Quentin Date: Thu, 28 Jun 2012 12:18:21 +0200 Subject: [PATCH] [feature] stdlib: String.fresh --- stdlib/core/string.opa | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/stdlib/core/string.opa b/stdlib/core/string.opa index b6fa9022..31e1226d 100644 --- a/stdlib/core/string.opa +++ b/stdlib/core/string.opa @@ -601,6 +601,24 @@ String = else source ^ "a" + /** + * Returns a string fresh generator. + */ + fresh(init : int) = + ofint(i) = + if (i <= 25) then String.of_utf8_val(i + 65) //Capital Letter + else String.of_utf8_val(i + 72) //Small Letter + rec gen(i, l) = + if (i <= 50) then String.flatten(ofint(i)+>l) + else + gen(i/50, ofint(mod(i, 50))+>l) + x = Reference.create(init) + // We don't use Fresh module (because cyclic-dependencies) + -> + i = Reference.get(x) + do Reference.set(x, i+1) + gen(i, []) + /** * Returns true iff the source string has a given prefix. *