1. If the intention is to create a class, then I'd use the class form. https://docs.racket-lang.org/reference/createclass.html#%28form._%28%28lib._racket%2Fprivate%2Fclass-internal..rkt%29._class%2A%29%29
Not that there's anything overtly wrong with using a closure, but common validation tasks re: inheritance, overriding, etc. all have to be done by hand here. 2. What specific error message did you get? ~slg ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Saturday, February 15, 2020 6:18 PM, Alain De Vos <devosalai...@gmail.com> wrote: > 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](https://groups.google.com/d/msgid/racket-users/c28892b8-e49b-4257-9ebe-4560943e87a7%40googlegroups.com?utm_medium=email&utm_source=footer). -- 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/gUC9HzrnJWNGbe-kgcoyov8KOUFY7sKw4KNu2CfqFABrsW0dsGpLsPfuKAHmcoXMBFECT4Bln1wQMYhpOFhL_y4WjYY-RWnveapTNESXHoc%3D%40sagegerard.com.