>>> However, generating the most optimal code may prove to be complicated. >>> For instance, you’d want: >>> >>> (set-fields p (person-address address-city) "Düsseldorf" >>> (person-address address-street) "Bar") >>> >>> to expand to: >>> >>> (set-person-address p >>> (let ((a (person-address p))) >>> (set-fields a (address-city) "Düsseldorf" >>> (address-street) "Bar"))) >>> >>> But that would require knowledge of the relationship between >>> ‘address-city’, ‘address-street’, and the underlying record type, etc. >> >> I don't understand why such knowledge is needed, or why this is >> difficult. We have procedural macros. Simply sort the field-name-paths >> lexicographically, split the sorted paths into groups with the same car, >> and recurse. Am I missing something? > > Yes: nothing forces you to prefix names with ‘address-’ here.
I might be wrong, but I don't think you need any knowledge of the names to make this work. In your example, the two field-name-paths are (person-address address-city) and (person-address address-street). They both have the car 'person-address, so you can pull that out to generate your expansion: (set-person-address p (let ((a (person-address p))) (set-fields a (address-city) "Düsseldorf" (address-street) "Bar"))) I think it could be implemented without any knowledge of the names at all. The lexicographical ordering is just a way to improve the performance of finding common prefixes. A hash table would also work. I hope this is useful, Noah