Created
May 22, 2009 09:42
-
-
Save liquidz/116034 to your computer and use it in GitHub Desktop.
まだ途中
This file contains 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
(use simply) | |
(define (klass klass-name . init) | |
(define (k2s k) | |
(string->symbol (keyword->string k)) | |
) | |
(let-keywords init ((initialize '()) | |
(prototype (make-hash-table*)) | |
) | |
(lambda arguments | |
(let1 this (make-hash-table*) | |
; inherit | |
(prototype :each (lambda (k v) (this k v))) | |
(if initialize (apply initialize (cons this arguments))) | |
(lambda command | |
(cond | |
[(null? command) | |
((this 'get) this) | |
] | |
[(keyword? (car command)) | |
(apply (this (k2s (car command))) (cons this (cdr command))) | |
] | |
) | |
) | |
) | |
) | |
) | |
) | |
(define (main args) | |
(let1 my-klass | |
(klass | |
'my-klass | |
:initialize (lambda (this name age) | |
(this 'name name) | |
(this 'age age) | |
) | |
:prototype (hash-table* | |
'name "neko" | |
'age 10 | |
'get (lambda (this) | |
(+ (this 'name) (this 'age)) | |
) | |
'print (lambda (this) | |
(print (this 'name) ": " (this 'age)) | |
) | |
) | |
) | |
(let1 xx (my-klass "inu" 8) | |
(xx :print) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment