From: ludo@gnu.org (Ludovic Courtès)
To: Nikita Karetnikov <nikita@karetnikov.org>
Cc: bug-guix@gnu.org
Subject: Re: guix-package --search
Date: Thu, 24 Jan 2013 22:14:12 +0100 [thread overview]
Message-ID: <87ip6mjnbv.fsf@gnu.org> (raw)
In-Reply-To: <87r4lb29sy.fsf@karetnikov.org> (Nikita Karetnikov's message of "Wed, 23 Jan 2013 10:33:50 -0500")
Nikita Karetnikov <nikita@karetnikov.org> skribis:
>> 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.
>
> 'regexp-exec' will raise an error if either 'synopsis' or 'description'
> is not a string. That's why I wrapped it in 'false-if-exception'.
OK.
>> For i18n, we should actually use (gettext (package-description
>> package)), likewise for synopsis. This way, that will search through
>> text in the user’s native language.
>
> I added it, but I haven't properly tested it. Also, there is
> 'remove-duplicates' that works in the REPL.
Yes, see below.
> +(define (find-packages-by-description rx)
> + "Search in SYNOPSIS and DESCRIPTION using RX. Return a list of
> +matching packages."
> + (define (remove-duplicates pred lst)
> + ;; Remove duplicates from sorted LST using PRED.
> + (cond ((null-list? lst) lst)
> + ((= (length lst) 1) lst)
> + ((= (length lst) 2)
> + (if (pred (first lst) (second lst)) (cdr lst) lst))
> + ((pred (first lst) (second lst))
> + (remove-duplicates pred (cdr lst)))
> + (else (cons (first lst) (remove-duplicates pred (cdr lst))))))
First, can you use ‘delete-duplicates’ from (srfi srfi-1) instead?
> + (define (same-location? p1 p2)
> + ;; Compare locations of two packages.
> + (eq? (package-location p1) (package-location p2)))
Here you need to use ‘equal?’, not ‘eq?’: ‘equal?’ checks for structural
equality, whereas ‘eq?’ checks for pointer equality (info "(guile) Equality").
> + (remove-duplicates
> + same-location?
> + (stable-sort
> + (fold-packages
> + (lambda (package result)
> + (if (or (false-if-exception
> + (regexp-exec rx (gettext (package-synopsis package))))
> + (false-if-exception
> + (regexp-exec rx (gettext (package-description package)))))
> + (cons package result)
> + result))
Instead of ‘false-if-exception’, I’d prefer:
(lambda (package result)
(define matches?
(cut regexp-exec rx <>))
(if (or (and=> (package-synopsis package)
(compose matches? gettext))
...
Other than that it looks good to me!
Could you please also add a couple of tests in tests/guix-package.sh,
and the corresponding doc in guix.texi?
Thanks!
Ludo’.
next prev parent reply other threads:[~2013-01-24 21:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-20 3:15 guix-package --search Nikita Karetnikov
2013-01-20 21:40 ` Nikita Karetnikov
2013-01-21 22:13 ` Ludovic Courtès
2013-01-23 15:33 ` Nikita Karetnikov
2013-01-24 21:14 ` Ludovic Courtès [this message]
2013-01-26 8:55 ` [PATCH] guix-package: Add '--search'. (was: guix-package --search) Nikita Karetnikov
2013-01-26 21:43 ` [PATCH] guix-package: Add '--search' Ludovic Courtès
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=87ip6mjnbv.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).