25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

26 lines
902 B

  1. (define-macro (define-class name-and-members . body)
  2. "Macro for creating simple classes."
  3. (let ((name (car name-and-members))
  4. (members (cdr name-and-members)))
  5. `(set-type!
  6. (define
  7. ;; The function definition
  8. (,(string->symbol (concat-strings "make-" (symbol->string name))) ,@members)
  9. ;; The docstring
  10. ,(concat-strings "This is the handle to an object of the class " (symbol->string name))
  11. ;; the body
  12. ,@body
  13. (let ,(zip members members)
  14. (set-type!
  15. (lambda args
  16. "This is the docs for the handle"
  17. (let ((op (eval (car args))))
  18. (if (procedure? op)
  19. (eval args)
  20. (eval (car args)))))
  21. ,(symbol->keyword name))))
  22. :constructor)))
  23. (define-macro (-> obj meth . args)
  24. `(,obj ',meth ,@args))