From: ludo@gnu.org (Ludovic Courtès)
To: Nikita Karetnikov <nikita@karetnikov.org>
Cc: bug-guix@gnu.org
Subject: Re: guix-package --roll-back
Date: Fri, 11 Jan 2013 14:39:59 +0100 [thread overview]
Message-ID: <87obgvale8.fsf@gnu.org> (raw)
In-Reply-To: <87vcb4jmm8.fsf@karetnikov.org> (Nikita Karetnikov's message of "Fri, 11 Jan 2013 00:48:29 -0500")
Hi,
Nikita Karetnikov <nikita@karetnikov.org> 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’.
next prev parent reply other threads:[~2013-01-11 13:40 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-21 22:49 guix-package --roll-back Nikita Karetnikov
2012-12-29 23:09 ` Nikita Karetnikov
2012-12-29 23:13 ` Andreas Enge
2012-12-30 15:30 ` Ludovic Courtès
2013-01-01 13:57 ` Nikita Karetnikov
2013-01-01 22:58 ` Ludovic Courtès
2013-01-03 5:42 ` Nikita Karetnikov
2013-01-03 14:41 ` Ludovic Courtès
2013-01-04 18:18 ` Nikita Karetnikov
2013-01-05 19:20 ` Ludovic Courtès
2013-01-09 19:04 ` Nikita Karetnikov
2013-01-10 15:01 ` Nikita Karetnikov
2013-01-10 22:26 ` Ludovic Courtès
2013-01-11 5:48 ` Nikita Karetnikov
2013-01-11 13:39 ` Ludovic Courtès [this message]
2013-01-12 21:03 ` Nikita Karetnikov
2013-01-13 20:40 ` Ludovic Courtès
2013-01-16 21:34 ` Nikita Karetnikov
2013-01-17 21:47 ` Ludovic Courtès
2013-01-21 5:50 ` Nikita Karetnikov
2013-01-22 21:37 ` 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=87obgvale8.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).