guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question regarding record types


From: Ludovic Courtès
Subject: Re: Question regarding record types
Date: Sun, 06 Nov 2016 18:24:31 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Hi!

Hartmut Goebel <address@hidden> skribis:

> in the services modules, there are configuration types defined like this:
>
> (define-record-type* <nginx-configuration>
>   nginx-configuration make-nginx-configuration
>   nginx-configuration?
>   (nginx         nginx-configuration-nginx)         ;<package>
>   (log-directory nginx-configuration-log-directory) ;string
>   (run-directory nginx-configuration-run-directory) ;string
>   (vhosts        nginx-configuration-vhosts
>                  (default '()))   ;list of <nginx-vhost-configuration>
>   (file          nginx-configuration-file))         ;string | file-like
>
> I wonder if it's really necessary to have this prefix
> "nginx-configuration-" for what I assume is the getter? For me it looks
> redundant. The getter is only valid for this very type, so why should
> there be any need to add a prefix?

A widespread Scheme convention is that, for a type T, the procedure to
access field F is called ‘T-G’.  So, ‘nginx-configuration-log-directory’
accesses the ‘log-directory’ field of an ‘nginx-configuration’ record.

Calling it simply ‘log-directory’ would be ambiguous and more likely to
lead to name clashes (Guile’s module system provides tools to
select/rename imported bindings, but still.)

In practice, what typically happens in the case of configuration records
is that (1) we use ‘match’ within the module, so we don’t have to use
the long names, and (2) we rarely have to use the long accessor names
outside.

Ludo’.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]