michaelmmacleod
2019-4-30 19:36:43

In the context of a class form, what’s the difference between define and define/private? They both seem to define identifiers that are inaccessible from outside the class and can’t be inherited in subclasses.


dan
2019-4-30 19:49:28

@michaelmmacleod In a class, define will create a private field which will be created for each instance of a class, whereas define/private is used to create private methods, so they’re shared by all objects a given class


lexi.lambda
2019-4-30 19:51:38

To add some extra detail to what Dan said, (define (f) ...) will create a private field that contains a lambda that closes over this (and the init args), so the closure will be reallocated every time the class is instantiated.


michaelmmacleod
2019-4-30 19:54:34

Thanks, that makes sense now. I guess I’ll try to use define/private whenever possible to avoid excess allocation.


lexi.lambda
2019-4-30 20:25:34

I’d bet it’s not actually a very important difference unless you’re making a lot of objects.