ifndef SymbolAsString sclass symbol_Tester { S text; *(S *text) {} public int hashCode() { ret main hashCode(text); } public bool equals(O o) { ret o instanceof Symbol && eq(text, o/Symbol.text); } } static WeakHashMap symbol_map = newWeakHashMap(); endifndef static Symbol symbol(S s) { ifdef SymbolAsString ret s; endifdef ifndef SymbolAsString if (s == null) null; synchronized(symbol_map) { // This is a trick that works because of how WeakHashMap compares keys. O e = call(symbol_map, 'getEntry, symbol_Tester(s)); Symbol sym = e == null ? null : ((WeakReference) e).get(); if (sym == null) symbol_map.put(sym = Symbol(s, false), Bool.TRUE); ret sym; } endifndef } static Symbol symbol(CharSequence s) { if (s == null) null; ifdef SymbolAsString ret str(s); endifdef ifndef SymbolAsString if (s instanceof Symbol) ret (Symbol) s; if (s instanceof S) ret symbol((S) s); ret symbol(str(s)); endifndef }