37 lines
667 B
Go
37 lines
667 B
Go
package symbol
|
|
|
|
var intern_map map[string]*Symbol
|
|
|
|
type Symbol struct {
|
|
ns string
|
|
symbol string
|
|
}
|
|
|
|
func Intern(ns string, symbol string) *Symbol {
|
|
combined_str := ns + "/" + symbol
|
|
existingSymbol, ok := intern_map[combined_str]
|
|
if ok {
|
|
return existingSymbol
|
|
} else {
|
|
newSymbol := new(Symbol)
|
|
newSymbol.ns = ns
|
|
newSymbol.symbol = symbol
|
|
if intern_map == nil {
|
|
intern_map = make(map[string]*Symbol)
|
|
}
|
|
intern_map[combined_str] = newSymbol
|
|
return newSymbol
|
|
}
|
|
}
|
|
|
|
func String(this *Symbol) string {
|
|
if this.ns == "" {
|
|
return this.symbol
|
|
}
|
|
return this.ns + "/" + this.symbol
|
|
}
|
|
|
|
func (this *Symbol) String() string {
|
|
return String(this)
|
|
}
|