From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nikita Karetnikov Subject: Re: New =?utf-8?Q?=E2=80=98--list-generations=E2=80=99?= and =?utf-8?Q?=E2=80=98--delete-generations=E2=80=99?= options Date: Sun, 08 Sep 2013 14:59:55 +0400 Message-ID: <87fvtfzihg.fsf@karetnikov.org> References: <87vc2o4qwc.fsf@gnu.org> <87y57kljro.fsf@karetnikov.org> <87hae81uvo.fsf@gnu.org> <87bo4fcbcz.fsf@karetnikov.org> <878uzj6nev.fsf@gnu.org> <877gf1yftq.fsf@karetnikov.org> <87bo4dspl2.fsf@gnu.org> <87a9jxeh05.fsf@gnu.org> <87r4d9r2lv.fsf@gnu.org> <874na4jfp4.fsf_-_@karetnikov.org> <87eh97616m.fsf@gnu.org> <87bo48xdgb.fsf@karetnikov.org> <87hadz9gze.fsf@gnu.org> <87fvtjdl7y.fsf@karetnikov.org> <87bo444e9q.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45023) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VIceN-0005Wf-Es for guix-devel@gnu.org; Sun, 08 Sep 2013 06:55:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VIceM-0005tU-IR for guix-devel@gnu.org; Sun, 08 Sep 2013 06:55:27 -0400 List-Id: 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 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > I=E2=80=99m asking because if we do that, =E2=80=98--list-generations=E2= =80=99 may just as well > print out *all* the generation records. Users who want to select only > less than one-month old generations can do that with =E2=80=98recsel=E2= =80=99, and we > don=E2=80=99t have anything more to do. > WDYT? I see recutils as an advanced option (for those who need it), not a replacement for the basic functionality. > OTOH, for =E2=80=98--delete-generations=E2=80=99 it will still be more co= nvenient to > support =E2=80=98--delete-generations=E2=80=99. Could you rephrase? I don=E2=80=99t understand the above. I believe we sh= ould think from a user=E2=80=99s perspective. One should be able to select the needed generations without relying on a different program. > I think you find it difficult to test because the parsing and generation > enumeration are intermingled. Right, I agree. >>> What about splitting it in two functions: >>> =E2=80=98string->time-range=E2=80=99 =E2=86=92 return two SRFI-19 tim= e objects representing a >>> time interval, or #f and #f on failure >>> =E2=80=98generation-within-time-range?=E2=80=99 >>> Writing tests for the former will be easy. > What do you think of the separation I proposed? We have the following cases: =E2=80=981=E2=80=99, =E2=80=981,2,3=E2=80=99, = =E2=80=981..9=E2=80=99, =E2=80=981..=E2=80=99, =E2=80=98..9=E2=80=99, =E2=80=98first-month=E2=80=99, and =E2=80=98last-month=E2=80=99. It=E2=80= =99s easy to parse the first three and output a list of generations without checking them. However, you=E2=80=99ll have to check the profile in the other cases. That=E2=80=99s the problem. It=E2=80=99s also possible to write something like this (untested): (define (available-generations str) (define (integer?*) (integer? (string->number str))) (define (comma-separated-integers?) (every integer? (delete-duplicates (map string->number (delete "" (string-split str #\,)))))) (define (safe-match:substring->number match n) (false-if-exception (string->number (match:substring match n)))) (define (maybe-whole-range-lst) (let* ((rx (make-regexp "^([0-9]+)\\.\\.([0-9]+)$")) (res (regexp-exec rx str)) (x (safe-match:substring->number res 1)) (y (safe-match:substring->number res 2))) (list x y))) (define (whole-range?) (let ((x (first maybe-whole-range-lst)) (y (last maybe-whole-range-lst))) (and (every integer? (maybe-whole-range-lst)) (<=3D x y)))) (define (maybe-start-range) (let* ((rx (make-regexp "^([0-9]+)\\.\\.$")) (res (regexp-exec rx str))) (safe-match:substring->number res 1))) (define (start-range?) (integer? (maybe-start-range))) ;; ... ) First, this is quite wordy. Moreover, we=E2=80=99ll have to move every definition to the global namespace if we want to test only syntax. I doubt that the above is the way to go. I don=E2=80=99t understand how the =E2=80=98string->time-range=E2=80=99 fun= ction will help to solve the above problem. There are only two time-related cases: =E2=80=98first-month=E2=80=99 and =E2=80=98last-month=E2=80=99. Why do you= want to return a time range for every case? Could you show an example? --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIcBAEBAgAGBQJSLFiuAAoJEM+IQzI9IQ38LgEP/iDAiDrmk78Axmz/v2jKesAt KFvbQUU0vk9Rx4yufkABzZIL9M9tO4uRLfisQ2VgPB/UYVw6HV5RpBYH6DH3tzP+ lUE8x4Pqm+B7xhhUkp2dBNvT233pml4St2iH6+xLXsWM7Vs/CwS450WP5tyARd7E pPW7BOi1bhOlrbHj9CeQIEOD+t/4gGRSScRky/tlZ7wgAgYwEAhmhC7Q4+Fhc+Jb sxkcUWwSv7ARt+7KPpzfNoGoxoMgMOnAA79xqv8iwNX8m6eNyAJvY9wcqhfrZgfV D8QBjM98ZqW69nfq4ZpWOinBh3z4+wELTfGErMxJ7Xp15ghXED0FSfp3mZXeOyzs c52nEwbH+V+z8+qBFw+QnvdlULWNXfmceBdvdoiMHq0m1xc8jm9HH58RZr+vEZV9 fMoS8WganSrzsFlKUuAIjs63/8/j2av0Vbz4fSWTPPoQBtQjeWYEI/QGJ/hQFvgJ FU7clE9ZKGly4xxdUHcFva7KmkewHR1JQJsJvp+JuwaNAojI0K0EmYcURO/WmnKe IKZpVT/wr+7qnKeBl0LPwgT4P8BxDwrwPt511N3TbYx5A6pSPKSb8Gi00CahMKOX DlubU/PvkyVPGTTa8leqwbhTBdENtsEQD9ijUeeQhWX+5O0AQFcpNsCISoyfMYFQ 8nBaf+xYOdQcUDNZXpOA =xCj6 -----END PGP SIGNATURE----- --=-=-=--