Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 19th, 2012  |  syntax: None  |  size: 0.52 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (define-syntax-rule (defobject (name) slot1 ...)
  2.   (begin
  3.     (define (name msg)
  4.       #|TODO: derive this from the slots of the root object, which would include clone,
  5.         to-string, etc|#
  6.       (define slots (make-hash))
  7.       ;;;This internal macro is currently useless
  8.       (define-syntax-rule (self x) (hash-ref slots 'x))
  9.       (for ([s '(slot1 ...)])
  10.         (hash-set! slots (first s) (eval (last s))))
  11.      
  12.       (hash-ref slots msg))))
  13.  
  14. (defobject (posn)
  15.   [x 2]
  16.   [y x]
  17.   [add (λ() (+ (posn 'x) (posn 'y)))])