Skip to content

Commit

Permalink
Implement String >> #uniq via (new) #uniqueVariableNameFor:
Browse files Browse the repository at this point in the history
  • Loading branch information
janvrany authored and shingarov committed May 22, 2024
1 parent b318dde commit cef75f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/SpriteLang/String.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ String >> unifyX: anotherString [
String >> uniq [
"Return new unique variable name suitable for
α-renaming."
^self, '__ß', VariableAlphabet nextJ printString
^VariableAlphabet uniqueVariableNameFor: self
]
16 changes: 16 additions & 0 deletions src/SpriteLang/VariableAlphabet.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Extension { #name : #VariableAlphabet }

{ #category : #'*SpriteLang' }
VariableAlphabet class >> uniqueVariableNameFor: original [
j isNil ifTrue: [ j:= 0 ].
j := j + 1.
^String streamContents: [ :s|
s nextPutAll: original.
s nextPutAll: '__ß'.
j printOn: s base: 10 nDigits: 6
].

"
VariableAlphabet uniqueVariableNameFor: 'x'
"
]

0 comments on commit cef75f5

Please sign in to comment.