
Today’s horrible code is provided to you by… #lang racket
(define (accessor-name accessor)
(define msg (with-handlers ([exn:fail? (λ (e) (exn-message e))]) (accessor 'a)))
(define m (regexp-match #px"^(.*): contract violation\n expected: (.*)\\?\n given: 'a$"
msg))
(define acc (second m))
(define s (third m))
(list (string->symbol acc)
(string->symbol s)
(string->symbol (substring acc (+ 1 (string-length s))))))
(struct mystruct (afield))
(accessor-name mystruct-afield) ; '(mystruct-afield mystruct afield)
Good thing exception messages are reliable :sweat_smile:

What’s your use case?

It would be nice to have everything in the compile-time struct info so that things like this is not necessary.

One thing that is on my wishlist is adding struct-name-info
, along the line of struct-field-info
that I just added.

Yeah, I’ve done that a couple of times. But today I was lazy and used the less invasive approach to transform some existing code

It’s very much not the first time I want that kind of info though, I wish it was available from racket core

Interestingly Squeak and Pharo from what I can see added traits to Smalltalk! Wonder when that happened. http://pharo.gforge.inria.fr/PBE1/PBE1ch6.html

Prototype OOP (Javascript, Self) and multiple dispatch OOP (CLOS, Julia) are also really interesting. It’s a shame how OOP is sometimes reduced to class-based single-dispatch Java-like OOP..!

@ahmadrasyidsalim has joined the channel

@robbiehk131 has joined the channel

I think multiple-dispatch is interesting, but there are reasons single dispatch is more dominant. It’s easier to reason about and implement correctly.