TIL: Inherited fields in structure subtypes are accessed with the accessor from the supertype

jamesgeddes
Wed, 04 May 2022 13:10:06 +0000
General

I thought you'd get at all fields in the subtype with accessors derived from the name of the subtype. No -- for supertype fields you use the supertype accessors.

For example, if:

A position is a pair of numbers: (struct posn (x y)); and

A 3d position is a kind of position, with an extra number: (struct 3d-posn posn (z))

Then the three components of (define p (3d-posn 10 20 30)) are:

(posn-x p), (posn-y p), and (3d-posn-z p).

not, say, (3d-posn-x p) as I had imagined.

The docs explain: 5 Programmer-Defined Datatypes

8 posts - 6 participants