<div dir="ltr"><div>Hi All,</div><div><br></div><div>If I have several structures, like the following:</div><div><br></div><div> (struct customer (name age foo))</div><div> (struct student (name age bar))</div><div><br>
</div><div>I choose the same representation for the `name` and `age` fields which are `string?` and `natural-number/c`. So I think I could just define a `name` accessor for both `customer-name` and `student-name` to save some typing. I have to define the accesors by hand like:</div>
<div><br></div><div> (define (name record)</div><div> (cond</div><div> ((customer? record) (customer-name record))</div><div> ((student? record) (student-name record))))</div><div> (define (age record)</div>
<div> (cond</div><div> ((customer? record) (customer-age record))</div><div> ((student? record) (student-age record))))</div><div><br></div><div>1. It's much repetitive work. Is there any built-in way to do these things?</div>
<div> I think macro can do these. But I'm trying to avoid macros as much as I could, because I don't trust myself in designing macros. </div><div><br></div><div>2. Is it good or bad style to use one accessor for different structs?</div>
<div><br></div><div>Thanks,</div><div>Ben</div><div><br></div></div>