* Question regarding record types
@ 2016-11-04 22:31 Hartmut Goebel
2016-11-06 17:24 ` Ludovic Courtès
0 siblings, 1 reply; 2+ messages in thread
From: Hartmut Goebel @ 2016-11-04 22:31 UTC (permalink / raw)
To: Guix-devel
Hi,
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?
If the reason is, that all these getters are defined globally, them I'm
astound, why there is no syntax like my_config->log-directory, which
would remove this redundancy.
--
Regards
Hartmut Goebel
| Hartmut Goebel | h.goebel@crazy-compilers.com |
| www.crazy-compilers.com | compilers which you thought are impossible |
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Question regarding record types
2016-11-04 22:31 Question regarding record types Hartmut Goebel
@ 2016-11-06 17:24 ` Ludovic Courtès
0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2016-11-06 17:24 UTC (permalink / raw)
To: Hartmut Goebel; +Cc: Guix-devel
Hi!
Hartmut Goebel <h.goebel@crazy-compilers.com> 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’.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-11-06 17:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-04 22:31 Question regarding record types Hartmut Goebel
2016-11-06 17:24 ` Ludovic Courtès
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).