Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 15th, 2012  |  syntax: None  |  size: 0.54 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Matrix := Object clone do(
  2.         sizeX := 0
  3.         sizeY := 0
  4.         dim := method(x, y, sizeX = x; sizeY = y; self items := List clone; items setSize(x * y))
  5.         set := method(x, y, value, check(x, y); items atPut(index(x, y), value))
  6.         get := method(x, y, check(x, y); items at(index(x, y)))
  7.         check := method(x, y, if(x >= sizeX or y >= sizeY, Exception raise("index error")))
  8.         index := method(x, y, x * sizeX + y)
  9. )
  10.  
  11. m := Matrix clone
  12. m dim(3, 3)
  13. m set(1, 2, "foo")
  14. m get(1, 2) println
  15. m get(2, 2) println
  16. m get(3, 3) println