Interoperability Macros for roos and racket/class
(require roos/class) | package: roos |
This module provides a compatibility layer between the roos object system and the standard racket/class system. It exports the macros send, ->, and new, which automatically dispatch to the appropriate implementation based on the type of the given object or class.
1 Macros
syntax
syntax
1.1 Comparison with other languages
In other languages, method invocation often uses compact notation:
Perl: $obj->method(args)
Python / Ruby / Java / JavaScript: obj.method(args)
C++: obj->method(args) or obj.method(args)
The -> macro serves a similar role within the s-expression syntax of Racket.
syntax
(require roos/class) ; instead of racket/class (define (t% x) (class object% (init-field (y* x)) (define/public (y) y*) (define/public (y! x) (set! y* x)) (define/public (f a) (* (send this y) a)) (super-new))) (def-roos (t x) this (supers) (y x) ((f a) (* (-> this y) a))) (displayln (let ((cl (t% 5))) (let ((o (new cl))) (= (send o f 2) 10)))) (displayln (let ((cl (t% 6))) (let ((o (new cl))) (= (-> o f 3) 18)))) (displayln (let ((o (new t 8))) (= (-> o f 4) 32))) (displayln (= (send (new t 4) f 2) 8))
2 Implementation Notes
The original Racket send and -> are renamed to old-send and old-> internally.
The Roos-aware macros detect the object or class type and route to the correct implementation.
new* is a helper macro that transforms arguments into (v x) form when needed.
3 Testing
The module includes an internal test suite using RackUnit. It validates consistent behavior of send, ->, and new across both Racket classes and Roos classes.