High-performance Ruby: faster Symbol.to_s
Note: updated with suggestion by trans.
class Symbol def to_s @str_rep || (@str_rep = id2name.freeze) end end
11374 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
class Symbol def to_s @str_rep || (@str_rep = id2name.freeze) end end
REBOL [ Title: "Unique symbol generator" ] gen-sym-ctx: context [ prefix: "&" counter: 0 clear: does [counter: 0] set-prefix: func [value] [prefix: form value] set 'gen-sym does [ counter: counter + 1 to word! join prefix counter ] ] repeat i 5 [print gen-sym] gen-sym-ctx/set-prefix 'G gen-sym-ctx/clear repeat i 5 [print gen-sym]