laurent.orseau
2020-9-6 07:48:47

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:


sorawee
2020-9-6 09:10:46

What’s your use case?


sorawee
2020-9-6 09:11:18

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


sorawee
2020-9-6 09:12:23

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


laurent.orseau
2020-9-6 09:15:31

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


laurent.orseau
2020-9-6 09:16:06

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


maxim_jaffe
2020-9-6 12:03:57

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


maxim_jaffe
2020-9-6 12:18:01

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
2020-9-6 17:32:39

@ahmadrasyidsalim has joined the channel


robbiehk131
2020-9-6 17:41:10

@robbiehk131 has joined the channel


samdphillips
2020-9-6 19:51:31

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