26 lines
883 B
Plaintext
26 lines
883 B
Plaintext
(define-syntax (define-class name-and-members . body)
|
|
"Macro for creating simple classes."
|
|
(let ((name (first name-and-members))
|
|
(members (rest name-and-members)))
|
|
`(set-type!
|
|
(define
|
|
;; The function definition
|
|
(,(string->symbol (concat-strings "make-" (symbol->string name))) @members)
|
|
;; The docstring
|
|
,(concat-strings "This is the handle to an object of the class " (symbol->string name))
|
|
;; the body
|
|
@body
|
|
(let ,(zip members members)
|
|
(set-type!
|
|
(lambda args
|
|
"This is the docs for the handle"
|
|
(let ((op (eval (first args))))
|
|
(if (procedure? op)
|
|
(eval args)
|
|
(eval (first args)))))
|
|
,(symbol->keyword name))))
|
|
:constructor)))
|
|
|
|
(define-syntax (-> obj meth . args)
|
|
`(,obj ',meth @args))
|