unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Bengt Richter <bokr@bokr.com>
To: Brendan Tildesley <mail@brendan.scot>
Cc: guix-devel <guix-devel@gnu.org>
Subject: Re: A better way to access records.
Date: Fri, 30 Oct 2020 12:04:16 +0100	[thread overview]
Message-ID: <20201030110416.GA5579@LionPure> (raw)
In-Reply-To: <487cea17-061a-2cc9-6b3e-7b688114d158@brendan.scot>

Hi Brendan,

On +2020-10-30 21:28:38 +1100, Brendan Tildesley wrote:
> From the little bit of SICP that I've done, I recall watching the lectures
> where
> they put a mage hat on and talk about the power of names. One could perhaps
> say
> the most powerful tool in a programming language is the ability to give
> something a name and then refer to those names.
> 
> In guix/guile, record types are  list of names given to some data.
> For example:
> 
> (define foo
>   (package
>    (name "bar")
>    (version "1.0")
>    ...)
> 
> Here we the names foo, name, version, that refer to things of interest. We
> can
> call foo easily enough to get the record, but we cannot refer to name or
> version so easily.  We instead have to use accessors like (package-name
> foo),
> which requires us to write foo each time explicitly and have repeat package-
> for each accessor.
> In the guix codebase, on many occasions there appear things like this:
> 
> (match-lambda
>     (($ <agetty-configuration> agetty tty term baud-rate auto-login
>         login-program login-pause? eight-bits? no-reset? remote?
> flow-control?
>         host no-issue? init-string no-clear? local-line extract-baud?
>         skip-login? no-newline? login-options chroot hangup? keep-baud?
> timeout
>         detect-case? wait-cr? no-hints? no-hostname? long-hostname?
>         erase-characters kill-characters chdir delay nice extra-options)
>      (list
>       ....
> 
> Here we have given some names to things, abandoned those names, and once
> again
> gone to the trouble of naming them again, in order, just for one local
> environment. We'd have to do it again to make use of it elsewhere, and I
> assume
> they would have to change if the record type it self needed to be updated.
> 
> Wouldn't be nice if we could just step inside a record type whenever we
> pleased?
> The above would be like this perhaps:
> 
> (let-from-record-type <agetty-configuration>
>  (list ...))
> 
> "let-from-record-type" i just made up since i dont know what it should be
> called.  Anyhow, it seems like we're stepping back a few centuries in
> computer
> science by needing to jump through these hoops.
> 
> The list of symbols can be retreived with (record-type-fields
> <agetty-configuration>), but I can't think of how one would write the above
> syntax.
> 
> Opinions?
> 
> 
>

    info guile record

may be useful :)

-- 
Regards,
Bengt Richter


  reply	other threads:[~2020-10-30 11:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-30 10:28 A better way to access records Brendan Tildesley
2020-10-30 11:04 ` Bengt Richter [this message]
2020-10-30 18:17 ` Taylan Kammer
2020-10-31 22:01 ` Ludovic Courtès
2020-11-13 11:24   ` Brendan Tildesley
  -- strict thread matches above, loose matches on Subject: below --
2020-10-30 10:49 Leo Prikler
2020-10-30 10:59 ` Brendan Tildesley
2020-10-30 19:47   ` Danny Milosavljevic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201030110416.GA5579@LionPure \
    --to=bokr@bokr.com \
    --cc=guix-devel@gnu.org \
    --cc=mail@brendan.scot \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).