Skip to content

Instantly share code, notes, and snippets.

@liquidz
Created May 22, 2009 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liquidz/116034 to your computer and use it in GitHub Desktop.
Save liquidz/116034 to your computer and use it in GitHub Desktop.
まだ途中
(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