Skip to content

Commit

Permalink
[feature] stdlib: String.fresh
Browse files Browse the repository at this point in the history
  • Loading branch information
BourgerieQuentin committed Jun 29, 2012
1 parent 5911e23 commit 256083d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions stdlib/core/string.opa
Expand Up @@ -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.
*
Expand Down

0 comments on commit 256083d

Please sign in to comment.