您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

30 行
1.0 KiB

  1. (define-syntax (define-class name members :rest body)
  2. "Macro for creating classes."
  3. (define (underscore sym)
  4. (string->symbol (concat-strings "_" (symbol->string sym))))
  5. (define underscored-members (map underscore members))
  6. ;; the wrapping let environment
  7. (define let-body `(let ,(zip members underscored-members)))
  8. ;; the body
  9. (extend let-body body)
  10. ;; (map (lambda (fun) (append let-body fun)) body)
  11. ;; the dispatch function
  12. (append let-body `(set-type
  13. (special-lambda
  14. (message :rest args)
  15. "This is the docs for the handle"
  16. (eval (extend (list message) args))) ,(symbol->keyword name)))
  17. ;; stuff it all in the constructor function
  18. `(define
  19. ;; The function definition
  20. ,(pair (string->symbol (concat-strings "make-" (symbol->string name))) underscored-members)
  21. ;; The docstring
  22. ,(concat-strings "This is the handle to an object of the class " (symbol->string name))
  23. ;; the body
  24. ,let-body))