Files
slime/bin/oo.slime
T
2020-02-18 10:52:05 +01:00

26 lines
911 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))