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 --roll-back Date: Fri, 11 Jan 2013 14:39:59 +0100 Message-ID: <87obgvale8.fsf@gnu.org> References: <871uejyq9z.fsf@karetnikov.org> <874nj4sbfe.fsf@karetnikov.org> <87y5gf8sm1.fsf@gnu.org> <87hamy4yaj.fsf@karetnikov.org> <87pq1m5nxy.fsf@gnu.org> <87obh43j7r.fsf@karetnikov.org> <87vcbbqvw1.fsf@gnu.org> <87fw2ai3e1.fsf@karetnikov.org> <8738y8ekst.fsf@gnu.org> <87vcb4jmm8.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]:40290) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tteq6-0003l8-Ul for bug-guix@gnu.org; Fri, 11 Jan 2013 08:40:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tteq1-00039N-Vf for bug-guix@gnu.org; Fri, 11 Jan 2013 08:40:05 -0500 Received: from mail4-relais-sop.national.inria.fr ([192.134.164.105]:56400) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tteq1-00038S-Ob for bug-guix@gnu.org; Fri, 11 Jan 2013 08:40:01 -0500 In-Reply-To: <87vcb4jmm8.fsf@karetnikov.org> (Nikita Karetnikov's message of "Fri, 11 Jan 2013 00:48:29 -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: > This one doesn't work at all: > > (option '("foo") #f #t > (lambda (opt name arg result) > (alist-cons 'foo arg result))) It actually does, but it has no side effect. =E2=80=98args-fold=E2=80=99 uses a common functional programming pattern, w= hereby the functions called when an option is encountered just /contribute/ to the resulting value. Here=E2=80=99s an example: --8<---------------cut here---------------start------------->8--- scheme@(guile-user)> (use-modules(srfi srfi-37)) scheme@(guile-user)> (define options (list (option '("foo") #f #t (lambda (opt name arg result) (if arg (cons arg result) 'nothing))))) scheme@(guile-user)> (args-fold '("--foo") options (const #f) (const #f) '(= something)) $19 =3D nothing scheme@(guile-user)> (args-fold '("--foo=3D42") options (const #f) (const #= f) '(something)) $20 =3D ("42" something) scheme@(guile-user)> (args-fold '("--foo=3D42" "--foo=3D3") options (const = #f) (const #f) '(something)) $21 =3D ("3" "42" something) scheme@(guile-user)> (args-fold '("--foo=3D42" "--foo=3D3" "--foo") options= (const #f) (const #f) '(something)) $22 =3D nothing --8<---------------cut here---------------end--------------->8--- In guix-package, =E2=80=98parse-options=E2=80=99 returns an alist (list of = pairs) that indicates the actions to be performed, etc. IOW, =E2=80=98args-fold=E2=80= =99 is a tool to build =E2=80=9Ctranslators=E2=80=9D from command-line options to an inte= rnal representation of those options. > Actually, the above helped me to understand that we want '--roll-back' > to behave differently than '--foo'. '--roll-back' shouldn't accept any > options at all, but it should somehow get the argument of '--profile'. > How can I do it? When =E2=80=98--profile=E2=80=99 is passed, the result of =E2=80=98parse-op= tions=E2=80=99 contains a pair whose key is =E2=80=98profile=E2=80=99. The (assoc-ref opts 'profile)= calls that you see retrieve the argument given to =E2=80=98--profile=E2=80=99. Ludo=E2=80=99.