From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: guix-package --search Date: Mon, 21 Jan 2013 23:13:24 +0100 Message-ID: <87obgi6v7f.fsf@gnu.org> References: <87libor1c9.fsf@karetnikov.org> <87r4lfr0r3.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]:55433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxPcQ-0003EK-7j for bug-guix@gnu.org; Mon, 21 Jan 2013 17:13:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TxPcN-0002NS-KW for bug-guix@gnu.org; Mon, 21 Jan 2013 17:13:30 -0500 Received: from mail4-relais-sop.national.inria.fr ([192.134.164.105]:33857) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxPcN-0002NK-DK for bug-guix@gnu.org; Mon, 21 Jan 2013 17:13:27 -0500 In-Reply-To: <87r4lfr0r3.fsf@karetnikov.org> (Nikita Karetnikov's message of "Sun, 20 Jan 2013 16:40:38 -0500") 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 Hi, Nikita Karetnikov skribis: > 1. 'psd-list' is a potential bottleneck. It will cause problems when we > have more packages. If it's possible to evaluate it lazily, I'll > rewrite it. (I haven't checked yet.) See below. [...] > 4. I've noticed that 'fold-packages' returns duplicates. Should it be > fixed? Should I filter the output instead? These are not really duplicates, actually: these are variants of the same packages, created using =E2=80=98inherit=E2=80=99, and keeping the ori= ginal package=E2=80=99s source location info (which could be fixed). That said, it would make sense to =E2=80=98delete-duplicates=E2=80=99 any t= wo packages whose =E2=80=98package-location=E2=80=99 are =E2=80=98eq?=E2=80=99. But th= at can be left as a separate commit. The patch looks good overall. A few comments: > +(define (sd-search rx) Rather =E2=80=98find-packages-by-description=E2=80=99 or similar. > + "Search in SYNOPSIS and DESCRIPTION using RX. Return a list of > +matching packages." > + (define psd-list > + ;; Return a list of lists (each inner list contains PACKAGE-NAME, > + ;; SYNOPSIS, and DESCRIPTION of every package). > + (map (lambda (x) > + (list x (package-synopsis x) (package-description x))) > + (fold-packages cons '()))) Instead, you can directly build the list of matching packages, like: (fold-packages (lambda (package result) (if (or (regexp-exec rx (package-synopsis package)) (regexp-exec rx (package-description package))) (cons package result) result)) '()) This way, only one traversal is done. For i18n, we should actually use (gettext (package-description package)), likewise for synopsis. This way, that will search through text in the user=E2=80=99s native language. > + (('search regexp) > + (let ((regexp (and regexp (make-regexp regexp)))) > + (for-each (lambda (p) > + (format #t "~a\t~a\t~a~%" > + (package-name p) > + (package-version p) > + (location->string (package-location p)))) > + (sd-search regexp)) > + #t)) Perfect. Thanks! Ludo=E2=80=99.