cs: make gensym
add a counter for the printed form
Although the counter doesn't make the generated symbol any more distinct, it's often a helpful hint. Closes #2396
This commit is contained in:
parent
df88852e24
commit
fd462604bd
|
@ -1,15 +1,24 @@
|
|||
|
||||
(define gensym
|
||||
(case-lambda
|
||||
[() (chez:gensym)]
|
||||
[() (#%gensym)]
|
||||
[(s) (cond
|
||||
[(string? s) (chez:gensym (string->immutable-string s))]
|
||||
[(symbol? s) (chez:gensym (chez:symbol->string s))]
|
||||
[(string? s) (#%gensym (append-gensym-counter s))]
|
||||
[(symbol? s) (#%gensym (append-gensym-counter (chez:symbol->string s)))]
|
||||
[else (raise-argument-error
|
||||
'gensym
|
||||
"(or/c symbol? string?)"
|
||||
s)])]))
|
||||
|
||||
(define gensym-counter (box 0))
|
||||
|
||||
(define (append-gensym-counter s)
|
||||
(let loop ()
|
||||
(let ([c (#%unbox gensym-counter)])
|
||||
(if (#%box-cas! gensym-counter c (add1 c))
|
||||
(string-append s (number->string c))
|
||||
(loop)))))
|
||||
|
||||
(define/who (symbol-interned? s)
|
||||
(check who symbol? s)
|
||||
(not (gensym? s)))
|
||||
|
|
Loading…
Reference in New Issue
Block a user