Hello, Tomas Volf <[email protected]> skribis:
>> There’s an important property of macros referred to as “hygiene” (a >> proper name would be “referential transparency”). One aspect of it is >> that any binding that is introduced must appear in the source. For >> example, ‘this-package’ appears as an argument to ‘define-record-type*’. >> Hence my question. > > Well, I assumed it could be done using datum->syntax, by putting > together this-package (or whatever user configured) with name of the > current field. But if that would be problem for some reason, you could > always just do > > (define-record-type* <package> > package make-package > package? > this-package > ... > (inputs package-inputs > (default '()) > (thunked this-package-inputs) ; <-- HERE > (sanitize sanitize-inputs)) > ...) Yeah, it could be this way. It’s a bit intrusive though; the most problematic part is that if the record type author forgets to provide this identifier, then there’s no way to write correct inheritance code. >> Besides, one might be tempted to think that: >> >> this-package-inputs = (package-inputs this-package) >> >> … which would not be the case. > > Wait, it is not? Ugh, my head starts to hurt a little. :) > > (package (inherit %base) > (inputs (package-inputs %base))) This is incorrect as I tried to explain in <https://codeberg.org/guix/guix/pulls/6955> and <https://issues.guix.gnu.org/50335>. > (package (inherit %base) > (inputs (package-inputs this-package))) This is infinite recursion. > (package (inherit %base) > (inputs inputs)) 👍 (It’s a no-op though.) > To a degree, I assume that could have been done as: > > (define-record-type* <package> > package make-package > package? > this-package > inherited-value ; <-- HERE Yeah, that could have worked too, though it would have to be done for each and every record type. Ludo’.
