From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: [PATCH] gnu-maintenance: Improve 'official-gnu-packages'; add the related procedures. Date: Fri, 22 Mar 2013 13:19:25 +0100 Message-ID: <87620jk4oi.fsf@gnu.org> References: <87obfchq38.fsf@karetnikov.org> <87sj4ok6sc.fsf@gnu.org> <87sj48gxzp.fsf_-_@karetnikov.org> <87lia09khe.fsf@gnu.org> <874ngbcfbl.fsf_-_@karetnikov.org> <87vc8rq6ol.fsf@gnu.org> <877gl0kye8.fsf@karetnikov.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:54016) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UJ0wb-0003Z3-Rk for bug-guix@gnu.org; Fri, 22 Mar 2013 08:19:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UJ0wa-0003Gf-00 for bug-guix@gnu.org; Fri, 22 Mar 2013 08:19:37 -0400 Received: from [2a01:e0b:1:123:ca0a:a9ff:fe03:271e] (port=59487 helo=xanadu.aquilenet.fr) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UJ0wZ-0003Ai-Oj for bug-guix@gnu.org; Fri, 22 Mar 2013 08:19:35 -0400 In-Reply-To: <877gl0kye8.fsf@karetnikov.org> (Nikita Karetnikov's message of "Fri, 22 Mar 2013 05:37:35 +0400") List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org To: Nikita Karetnikov Cc: bug-guix@gnu.org Nikita Karetnikov 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. =E2=80=9CEval is evil=E2=80=9D, as lispers love to say. It should never be= used, unless there=E2=80=99s a very good reason to do so. In my unfinished binary substitute where a similar situation arises, I=E2=80=99ve 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) =3D> (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 =E2=80=98fields->alist=E2=80=99, which returns a li= st of key/value pairs. Then =E2=80=98alist->record=E2=80=99 converts that alist into a record. In= this example, it calls =E2=80=98%make-cache=E2=80=99 in a way equivalent to: (%make-cache (assoc-ref properties "StoreDir") (assoc-ref properties "WantMassQuery")) Here =E2=80=98%make-cache=E2=80=99 is the =E2=80=98normal=E2=80=99 SRFI-9 c= onstructor, which is called =E2=80=98make-gnu-package-descriptor=E2=80=99 in your code. Let me know if you need more details. Thanks, Ludo=E2=80=99.