Skip to content

Instantly share code, notes, and snippets.

@alexnask
Created July 3, 2012 11:55
Show Gist options
  • Select an option

  • Save alexnask/3039317 to your computer and use it in GitHub Desktop.

Select an option

Save alexnask/3039317 to your computer and use it in GitHub Desktop.
ooc symbol implementation
import structs/ArrayList
Symbol: class {
value: String
table: static ArrayList<This>
new: static func(.value) -> const This {
if(!table) table = ArrayList<This> new()
for(sym in table) {
if(sym value == value) return sym
}
this := This alloc() as This
this value = value
table add(this)
this
}
toString: func -> String { value }
toInt: func -> Int { this as Int }
}
import Symbol
Symbol new("foo") toInt() toString() println()
Symbol new("foo") toInt() toString() println()
// The same number should be printed both times
// :foo should translate to Symbol new("foo")
// Same with :"foo"
@nddrylliog
Copy link
Copy Markdown

An ArrayList? Seriously? What about a HashMap instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment