unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: A better way to access records.
@ 2020-10-30 10:49 Leo Prikler
  2020-10-30 10:59 ` Brendan Tildesley
  0 siblings, 1 reply; 8+ messages in thread
From: Leo Prikler @ 2020-10-30 10:49 UTC (permalink / raw)
  To: mail; +Cc: guix-devel

Well, the "functional" way of accessing them all in one go would be to 
  (map (cute <> foo) (list package-name package-version package-...))
But I assume you want syntax like

(let-field record field exp*)
(let-fields record (field1 field2...) exp*)

analogous to (srfi srfi-9 gnu) set-field and set-fields, am I right?

Regards, Leo



^ permalink raw reply	[flat|nested] 8+ messages in thread
* A better way to access records.
@ 2020-10-30 10:28 Brendan Tildesley
  2020-10-30 11:04 ` Bengt Richter
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Brendan Tildesley @ 2020-10-30 10:28 UTC (permalink / raw)
  To: guix-devel

 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?




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-11-13 11:25 UTC | newest]

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

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).