Following code makes an "integerclass" with an "add" method :
#lang racket (define (integerclass x) (define (getx) x) (define (setx! x_new) (set! x x_new)) (define (add y)(integerclass (+ x (y 'getx)))) (lambda (message . args) (case message ((getx) (apply getx args)) ((setx!) (apply setx! args)) ((add) (apply add args)) (else (error "POINT: Unknown message ->" message))))) (define (myprint x) (print x)(newline)) (define p1 (integerclass 1)) (myprint (p1 'getx)) (define p2 (integerclass 2)) (myprint (p2 'getx)) (define p3 (p1 'add p2)) (myprint (p3 'getx)) Question 1 : can this code be inproved, are there "better patterns" one can you. Question 2 : can i modify this code to use typed/racket. I tried but failed on the "apply" method in the code. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/c28892b8-e49b-4257-9ebe-4560943e87a7%40googlegroups.com.