[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: guix-package --roll-back
From: |
Ludovic Courtès |
Subject: |
Re: guix-package --roll-back |
Date: |
Fri, 11 Jan 2013 14:39:59 +0100 |
User-agent: |
Gnus/5.130005 (Ma Gnus v0.5) Emacs/24.2 (gnu/linux) |
Hi,
Nikita Karetnikov <address@hidden> 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.
‘args-fold’ uses a common functional programming pattern, whereby the
functions called when an option is encountered just /contribute/ to the
resulting value.
Here’s 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 = nothing
scheme@(guile-user)> (args-fold '("--foo=42") options (const #f) (const #f)
'(something))
$20 = ("42" something)
scheme@(guile-user)> (args-fold '("--foo=42" "--foo=3") options (const #f)
(const #f) '(something))
$21 = ("3" "42" something)
scheme@(guile-user)> (args-fold '("--foo=42" "--foo=3" "--foo") options (const
#f) (const #f) '(something))
$22 = nothing
--8<---------------cut here---------------end--------------->8---
In guix-package, ‘parse-options’ returns an alist (list of pairs) that
indicates the actions to be performed, etc. IOW, ‘args-fold’ is a tool
to build “translators” from command-line options to an internal
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 ‘--profile’ is passed, the result of ‘parse-options’ contains a
pair whose key is ‘profile’. The (assoc-ref opts 'profile) calls that
you see retrieve the argument given to ‘--profile’.
Ludo’.
- Re: guix-package --roll-back, Nikita Karetnikov, 2013/01/01
- Re: guix-package --roll-back, Nikita Karetnikov, 2013/01/03
- Re: guix-package --roll-back, Ludovic Courtès, 2013/01/03
- Re: guix-package --roll-back, Nikita Karetnikov, 2013/01/04
- Re: guix-package --roll-back, Ludovic Courtès, 2013/01/05
- Re: guix-package --roll-back, Nikita Karetnikov, 2013/01/09
- Re: guix-package --roll-back, Nikita Karetnikov, 2013/01/10
- Re: guix-package --roll-back, Ludovic Courtès, 2013/01/10
- Re: guix-package --roll-back, Nikita Karetnikov, 2013/01/11
- Re: guix-package --roll-back,
Ludovic Courtès <=
- Re: guix-package --roll-back, Nikita Karetnikov, 2013/01/12
- Re: guix-package --roll-back, Ludovic Courtès, 2013/01/13
- Re: guix-package --roll-back, Nikita Karetnikov, 2013/01/16
- Re: guix-package --roll-back, Ludovic Courtès, 2013/01/17
- Re: guix-package --roll-back, Nikita Karetnikov, 2013/01/21
- Re: guix-package --roll-back, Ludovic Courtès, 2013/01/22