From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Kost Subject: Re: [SHEPHERD] [PATCH] service: Improve 'service-list'. Date: Mon, 25 Jan 2016 18:57:18 +0300 Message-ID: <874me18xep.fsf@gmail.com> References: <1453649591-3478-1-git-send-email-alezost@gmail.com> <87oacak73e.fsf@gnu.org> <87powqdpdm.fsf_-_@gmail.com> <8737tln1fj.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNjW8-0003TO-8N for guix-devel@gnu.org; Mon, 25 Jan 2016 10:57:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aNjW5-0000Wx-04 for guix-devel@gnu.org; Mon, 25 Jan 2016 10:57:24 -0500 In-Reply-To: <8737tln1fj.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Mon, 25 Jan 2016 16:06:40 +0100") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel@gnu.org Ludovic Court=C3=A8s (2016-01-25 18:06 +0300) wrote: > Alex Kost skribis: > >> From f3d21e3ec8a100a966153d03264639ebe48e8872 Mon Sep 17 00:00:00 2001 >> From: Alex Kost >> Date: Mon, 25 Jan 2016 11:18:00 +0300 >> Subject: [PATCH] service: Improve 'service-list'. >> >> * modules/shepherd/service.scm (service-list): Use >> 'lookup-canonical-service' on each name instead of removing duplicates >> from the final list. > > [...] > >> diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm >> index f84d1dd..94f2aae 100644 >> --- a/modules/shepherd/service.scm >> +++ b/modules/shepherd/service.scm >> @@ -871,12 +871,13 @@ Return #f if service is not found." >>=20=20 >> (define (service-list) >> "Return the list of services currently defined." >> - (delete-duplicates >> - (hash-fold (lambda (key services result) >> - (append services result)) >> - '() >> - %services) >> - eq?)) >> + (hash-fold (lambda (name services result) >> + (let ((service (lookup-canonical-service name services))) >> + (if service >> + (cons service result) >> + result))) >> + '() >> + %services)) > > OK, except that we know that SERVICE is necessarily true, because the > canonical service for NAME is necessarily among SERVICES. > > So I would remove the =E2=80=98if=E2=80=99 and add a comment explaining t= he above. > > OK with this change? No, the service is not necessarily true. When a service has several names (e.g., "root" and "shepherd"), then %services table will contain 2 entries (with 'root' and 'shepherd' keys and the same (#< =E2=80= =A6>) value). So for one of the hash-table entries: (lookup-canonical-service 'root (list root-service)) returns #t, and for the other: (lookup-canonical-service 'shepherd (list root-service)) it returns #f. --=20 Alex