Created
April 2, 2009 19:52
-
-
Save pete/89395 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; 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