Page:Ludovic Courtès - Functional Package Management with Guix.djvu/5




 * Figure 4: A package definition using the high-level interface.

field names to field indexes, such that that mapping incurs no run-time overhead, in a way similar to SRFI-35 records. They also bind fields as per, allowing them to refer to one another, as on line 8 of Figure 4. The base32 macro simply converts a literal string containing a base-32 representation into a bytevector literal, again allowing the conversion and error-checking to be done at expansion time rather than at run-time.


 * Figure 5: Definition of the package record type.

The  and   macros are generated by a   hygienic macro,  , which is layered above SRFI-9’s syntactic record layer. Figure 5 shows the definition of the  record type (the   record type, not shown here, is defined similarly.) In addition to the name of a procedural constructor, , as with SRFI-9, the name of a syntactic constructor,  , is given (likewise,   is the syntactic constructor of  .) Fields may have a default value, introduced with the   keyword. An interesting use of default values is the  field: its default value is the result of , which is itself a built-in macro that expands to the source file location of the   form. Thus, records defined with the  macro automatically have a   field denoting their source file location. This allows the user interface to report source file location in error messages and in package search results, thereby making it easier for users to "jump into" the distribution’s source, which is one of our goals.


 * Figure 6: Creating a variant of the  package.

The syntactic constructors generated by  additionally support a form of functional setters (sometimes referred to as "lenses" ), via the   keyword. It allows programmers to create new instances that differ from an existing instance by one or more field values. A typical use case is shown in Figure 6: the expression shown evaluates to a new  instance whose fields all have