From: Matt Wette <matthew.wette@verizon.net>
To: Andy Wingo <wingo@pobox.com>
Cc: ludo@gnu.org, 21698@debbugs.gnu.org
Subject: bug#21698: accessing multiple flagged values with (ice-9 getopt-long)
Date: Fri, 24 Jun 2016 08:21:11 -0700 [thread overview]
Message-ID: <71713D65-96AD-4729-96AF-31828E3D3186@verizon.net> (raw)
In-Reply-To: <878txufxj9.fsf@pobox.com>
Thanks for the pointer. I can work with SRFI-37. I am OK w/ rejection of the patch. — Matt
> On Jun 24, 2016, at 7:53 AM, Andy Wingo <wingo@pobox.com> wrote:
>
> Hi Matt,
>
> Thanks for the patch. My instinct however is to point you towards
> SRFI-37, which in addition to supporting multiple argument values can
> also be used to fold over the precise argument order. I just don't know
> that we should be expanding (ice-9 getopt-long); it has its use case and
> if your needs go beyond it, then probably your needs go way beyond it.
>
> https://www.gnu.org/software/guile/manual/html_node/SRFI_002d37.html
>
> Ludovic, second opinions?
>
> Andy
>
> On Sat 17 Oct 2015 19:05, Matt Wette <matthew.wette@verizon.net> writes:
>
>> This is in reference to guile-2.0.11.
>>
>> The (ice-9 getopt-long) module does not provide a process for
>> accessing multiple command line arguments.
>>
>> A patch for ice-9/getopt-long.scm is attached which adds the procedure
>> getopt-ref/many to access multiple argument values.
>>
>> The following program and results illustrate the use of the current
>> getopt-ref and the proposed getopt-ref/many:
>>
>> mwette$ ./gotest.scm -f foo1 -b bar1 -f foo2 baz1 baz2
>>
>> program arguments:
>>
>> ("./gotest.scm" "-f" "foo1" "-b" "bar1" "-f" "foo2" "baz1" "baz2")
>>
>> getopt using option-ref:
>>
>> foo: "foo2"
>>
>> bar: "bar1"
>>
>> getopt using option-ref/many:
>>
>> foo: ("foo1" "foo2")
>>
>> bar: "bar1"
>>
>> where
>>
>> mwette$ cat gotest.scm
>>
>> #!/opt/local/bin/guile
>>
>> !#
>>
>> (use-modules (ice-9 getopt-long))
>>
>> (define spec
>>
>> '((foo (single-char #\f) (value #t))
>>
>> (bar (single-char #\b) (value #t))))
>>
>> (let* ((args (program-arguments))
>>
>> (opts (getopt-long args spec)))
>>
>> (simple-format #t "program arguments:\n")
>>
>> (simple-format #t "~S\n" args)
>>
>> (simple-format #t "\ngetopt using option-ref:\n")
>>
>> (simple-format #t "foo: ~S\n" (option-ref opts 'foo #f))
>>
>> (simple-format #t "bar: ~S\n" (option-ref opts 'bar #f))
>>
>> (simple-format #t "\ngetopt using option-ref/many:\n")
>>
>> (simple-format #t "foo: ~S\n" (option-ref/many opts 'foo #f))
>>
>> (simple-format #t "bar: ~S\n" (option-ref/many opts 'bar #f))
>>
>> )
>>
>>
>>
>> *** getopt-long.scm-orig 2015-10-15 06:40:29.000000000 -0700
>> --- getopt-long.scm 2015-10-17 09:42:41.000000000 -0700
>> ***************
>> *** 154,159 ****
>> --- 154,173 ----
>> ;;; (option-ref (getopt-long ...) 'x-includes 42) => "/usr/include"
>> ;;; (option-ref (getopt-long ...) 'not-a-key! 31) => 31
>>
>> + ;;; (option-ref/many OPTIONS KEY DEFAULT)
>> + ;;; Return value in alist OPTIONS using KEY, a symbol; or DEFAULT if not
>> + ;;; found. If multiple arg-options provided a list is returned. The value
>> + ;;; is either a string, a list or `#t'.
>> + ;;;
>> + ;;; For example, if the above was executed with multiple x-includes flags,
>> + ;;; then all will be returned in a list:
>> + ;;;
>> + ;;; (getopt-long '("my-prog" "-vk" "/tmp" "foo1" "--x-includes=/usr/include"
>> + ;;; "--x-includes=/opt/includd" "--" "-fred" "foo2" "foo3")
>> + ;;; grammar)
>> + ;;; (option-ref/many (getopt-long ...) 'x-includes 42)
>> + ;;; => ("/usr/include" "/opt/include")
>> +
>> ;;; Code:
>>
>> (define-module (ice-9 getopt-long)
>> ***************
>> *** 162,168 ****
>> #:use-module (ice-9 match)
>> #:use-module (ice-9 regex)
>> #:use-module (ice-9 optargs)
>> ! #:export (getopt-long option-ref))
>>
>> (define %program-name (make-fluid "guile"))
>> (define (program-name)
>> --- 176,182 ----
>> #:use-module (ice-9 match)
>> #:use-module (ice-9 regex)
>> #:use-module (ice-9 optargs)
>> ! #:export (getopt-long option-ref option-ref/many))
>>
>> (define %program-name (make-fluid "guile"))
>> (define (program-name)
>> ***************
>> *** 368,371 ****
>> --- 382,397 ----
>> The value is either a string or `#t'."
>> (or (assq-ref options key) default))
>>
>> + (define (option-ref/many options key default)
>> + "Return value, or values, in alist OPTIONS using KEY, a symbol; or DEFAULT if not found.
>> + The value is either a string, a list or `#t'."
>> + (let loop ((rez #f) (opts options))
>> + (if (null? opts) (or rez default)
>> + (if (eq? key (caar opts))
>> + (cond
>> + ((pair? rez) (loop (cons (cdar opts) res) (cdr opts)))
>> + (rez (loop (list (cdar opts) rez) (cdr opts)))
>> + (else (loop (cdar opts) (cdr opts))))
>> + (loop rez (cdr opts))))))
>> +
>> ;;; getopt-long.scm ends here
next prev parent reply other threads:[~2016-06-24 15:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-17 17:05 bug#21698: accessing multiple flagged values with (ice-9 getopt-long) Matt Wette
2016-06-24 14:53 ` Andy Wingo
2016-06-24 15:21 ` Matt Wette [this message]
2016-06-24 15:30 ` Ludovic Courtès
2016-06-24 17:14 ` Andy Wingo
2016-06-25 0:12 ` Matt Wette
2016-06-25 8:07 ` Andy Wingo
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://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=71713D65-96AD-4729-96AF-31828E3D3186@verizon.net \
--to=matthew.wette@verizon.net \
--cc=21698@debbugs.gnu.org \
--cc=ludo@gnu.org \
--cc=wingo@pobox.com \
/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.
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).