From: ludo@gnu.org (Ludovic Courtès)
To: Nikita Karetnikov <nikita@karetnikov.org>
Cc: bug-guix@gnu.org
Subject: Re: [PATCH] gnu-maintenance: Improve 'official-gnu-packages'; add the related procedures.
Date: Fri, 22 Mar 2013 13:19:25 +0100 [thread overview]
Message-ID: <87620jk4oi.fsf@gnu.org> (raw)
In-Reply-To: <877gl0kye8.fsf@karetnikov.org> (Nikita Karetnikov's message of "Fri, 22 Mar 2013 05:37:35 +0400")
Nikita Karetnikov <nikita@karetnikov.org> skribis:
> But it doesn't work. These lines rise an error:
>
> + (cons (gnu-package-descriptor
> + (inherit (first state))
> + ((eval (match-field str)
> + (interaction-environment)) str))
>
> (There may be other problems. For instance, it should remove fields'
> names from 'str' before creating a record.)
>
> What do you think about the 'eval' idea? It's used to avoid unnecessary
> repetition.
“Eval is evil”, as lispers love to say. It should never be used, unless
there’s a very good reason to do so.
In my unfinished binary substitute where a similar situation arises,
I’ve done this:
(define (fields->alist port)
"Read recutils-style record from PORT and return them as a list of key/value
pairs."
(define field-rx
(make-regexp "^([[:graph:]]+): (.*)$"))
(let loop ((line (read-line port))
(result '()))
(cond ((eof-object? line)
(reverse result))
((regexp-exec field-rx line)
=>
(lambda (match)
(cons (match:substring match 1)
(match:substring match 2))))
(else
(error "unmatched line" line)))))
(define (alist->record alist make keys)
"Apply MAKE to the values associated with KEYS in ALIST."
(let ((args (map (cut assoc-ref alist <>) keys)))
(apply make args)))
And then, it is used like this:
(alist->record properties
(cut %make-cache url <...>)
'("StoreDir" "WantMassQuery"))
To summarize, the input port containing a list of key/value pairs (like
yours) is first read by ‘fields->alist’, which returns a list of
key/value pairs.
Then ‘alist->record’ converts that alist into a record. In this
example, it calls ‘%make-cache’ in a way equivalent to:
(%make-cache (assoc-ref properties "StoreDir")
(assoc-ref properties "WantMassQuery"))
Here ‘%make-cache’ is the ‘normal’ SRFI-9 constructor, which is called
‘make-gnu-package-descriptor’ in your code.
Let me know if you need more details.
Thanks,
Ludo’.
next prev parent reply other threads:[~2013-03-22 12:19 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-22 5:29 [PATCH] gnu-maintenance: Add 'find-package-with-attrs' and '%package-list' Nikita Karetnikov
2013-02-22 10:00 ` Ludovic Courtès
2013-03-06 18:54 ` [PATCH] gnu-maintenance: Replace 'official-gnu-packages' with 'find-packages' Nikita Karetnikov
2013-03-06 23:28 ` Ludovic Courtès
2013-03-16 19:30 ` [PATCH] gnu-maintenance: Improve 'official-gnu-packages'; add the related procedures Nikita Karetnikov
2013-03-16 23:13 ` Ludovic Courtès
2013-03-22 1:37 ` Nikita Karetnikov
2013-03-22 10:08 ` Brandon Invergo
2013-03-22 12:30 ` Ludovic Courtès
2013-03-22 12:19 ` Ludovic Courtès [this message]
2013-03-26 20:22 ` Nikita Karetnikov
2013-03-26 20:50 ` Ludovic Courtès
2013-03-26 20:59 ` Nikita Karetnikov
2013-03-26 21:21 ` Ludovic Courtès
2013-03-27 6:05 ` Nikita Karetnikov
2013-03-27 10:08 ` Ludovic Courtès
2013-03-31 22:50 ` Ludovic Courtès
2013-03-26 20:49 ` Nikita Karetnikov
2013-03-26 21:02 ` Ludovic Courtès
2013-03-28 2:08 ` [PATCH] gnu-maintenance: Improve 'official-gnu-packages'; add " Nikita Karetnikov
2013-03-28 16:48 ` Ludovic Courtès
2013-03-28 22:40 ` Nikita Karetnikov
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=87620jk4oi.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=bug-guix@gnu.org \
--cc=nikita@karetnikov.org \
/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).