Skip to content

Instantly share code, notes, and snippets.

@pete
Created April 2, 2009 19:52
Show Gist options
  • Save pete/89395 to your computer and use it in GitHub Desktop.
Save pete/89395 to your computer and use it in GitHub Desktop.
; A demonstration of OO in Roboto
; Class definition:
(= Timer (Class 'new
(bind ()
(def new upto
(bind ((upto upto) (ticks 0))))
(def tick ()
(+= ticks 1)
(%= ticks upto)))))
; Instantiation
(= t (Timer 'new 10))
; Method calls
((t 'tick))
; Instance (singleton) methods:
(t 'set 'rolled? (lambda () (== ticks 0)))
; Overrides:
(t '(def tick () (bind (s nil) (= s (super)) (if rolled? "Ding" ticks))))
; Re-opening classes:
(Timer '(def upto= n (= upto n)))
(t 'upto= 5)
; "Including" modules.
(Timer 'merge! File)
(t 'readlines "/etc/passwd") ; WHY?!
; Multiple inheritance:
(= FileTimer (merge Timer File)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment