GNU bug report logs - #21698
accessing multiple flagged values with (ice-9 getopt-long)

Previous Next

Package: guile;

Reported by: Matt Wette <matthew.wette <at> verizon.net>

Date: Sat, 17 Oct 2015 18:29:02 UTC

Severity: normal

Done: Andy Wingo <wingo <at> pobox.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 21698 in the body.
You can then email your comments to 21698 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#21698; Package guile. (Sat, 17 Oct 2015 18:29:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Matt Wette <matthew.wette <at> verizon.net>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sat, 17 Oct 2015 18:29:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Matt Wette <matthew.wette <at> verizon.net>
To: bug-guile <at> gnu.org
Cc: Matthew Wette <matthew.wette <at> verizon.net>
Subject: accessing multiple flagged values with (ice-9 getopt-long)
Date: Sat, 17 Oct 2015 10:05:53 -0700
[Message part 1 (text/plain, inline)]
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))
  )
[Message part 2 (text/html, inline)]
[getopt-long.patch (application/octet-stream, attachment)]
[Message part 4 (text/html, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#21698; Package guile. (Fri, 24 Jun 2016 14:54:02 GMT) Full text and rfc822 format available.

Message #8 received at 21698 <at> debbugs.gnu.org (full text, mbox):

From: Andy Wingo <wingo <at> pobox.com>
To: Matt Wette <matthew.wette <at> verizon.net>
Cc: ludo <at> gnu.org, 21698 <at> debbugs.gnu.org
Subject: Re: bug#21698: accessing multiple flagged values with (ice-9
 getopt-long)
Date: Fri, 24 Jun 2016 16:53:46 +0200
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 <at> 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




Information forwarded to bug-guile <at> gnu.org:
bug#21698; Package guile. (Fri, 24 Jun 2016 15:22:02 GMT) Full text and rfc822 format available.

Message #11 received at 21698 <at> debbugs.gnu.org (full text, mbox):

From: Matt Wette <matthew.wette <at> verizon.net>
To: Andy Wingo <wingo <at> pobox.com>
Cc: ludo <at> gnu.org, 21698 <at> debbugs.gnu.org
Subject: Re: bug#21698: accessing multiple flagged values with (ice-9
 getopt-long)
Date: Fri, 24 Jun 2016 08:21:11 -0700
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 <at> 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 <at> 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





Information forwarded to bug-guile <at> gnu.org:
bug#21698; Package guile. (Fri, 24 Jun 2016 15:31:01 GMT) Full text and rfc822 format available.

Message #14 received at 21698 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Andy Wingo <wingo <at> pobox.com>
Cc: Matt Wette <matthew.wette <at> verizon.net>, 21698 <at> debbugs.gnu.org
Subject: Re: bug#21698: accessing multiple flagged values with (ice-9
 getopt-long)
Date: Fri, 24 Jun 2016 17:30:36 +0200
Hello,

Andy Wingo <wingo <at> pobox.com> skribis:

> 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?

Seconded.  I think we should probably “freeze” (ice-9 getopt-long) and
recommend SRFI-37.

Ludo’.




Reply sent to Andy Wingo <wingo <at> pobox.com>:
You have taken responsibility. (Fri, 24 Jun 2016 17:15:01 GMT) Full text and rfc822 format available.

Notification sent to Matt Wette <matthew.wette <at> verizon.net>:
bug acknowledged by developer. (Fri, 24 Jun 2016 17:15:01 GMT) Full text and rfc822 format available.

Message #19 received at 21698-done <at> debbugs.gnu.org (full text, mbox):

From: Andy Wingo <wingo <at> pobox.com>
To: ludo <at> gnu.org (Ludovic Courtès)
Cc: 21698-done <at> debbugs.gnu.org, Matt Wette <matthew.wette <at> verizon.net>
Subject: Re: bug#21698: accessing multiple flagged values with (ice-9
 getopt-long)
Date: Fri, 24 Jun 2016 19:14:28 +0200
On Fri 24 Jun 2016 17:30, ludo <at> gnu.org (Ludovic Courtès) writes:

> Andy Wingo <wingo <at> pobox.com> skribis:
>
>> 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?
>
> Seconded.  I think we should probably “freeze” (ice-9 getopt-long) and
> recommend SRFI-37.

Okeydoke, closing.  Thanks!

Andy




Information forwarded to bug-guile <at> gnu.org:
bug#21698; Package guile. (Sat, 25 Jun 2016 00:13:02 GMT) Full text and rfc822 format available.

Message #22 received at 21698 <at> debbugs.gnu.org (full text, mbox):

From: Matt Wette <matthew.wette <at> verizon.net>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: Andy Wingo <wingo <at> pobox.com>, 21698 <at> debbugs.gnu.org
Subject: Re: bug#21698: accessing multiple flagged values with (ice-9
 getopt-long)
Date: Fri, 24 Jun 2016 17:12:06 -0700
> On Jun 24, 2016, at 8:30 AM, Ludovic Courtès <ludo <at> gnu.org> wrote:
> 
> Hello,
> 
> Andy Wingo <wingo <at> pobox.com> skribis:
> 
>> 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?
> 
> Seconded.  I think we should probably “freeze” (ice-9 getopt-long) and
> recommend SRFI-37.

Agree.  Could you at the least add a reference to SRFI-37 in the section on (ice-9 getopt-long), in case you don’t go further — e.g., replace it?

Matt





Information forwarded to bug-guile <at> gnu.org:
bug#21698; Package guile. (Sat, 25 Jun 2016 08:08:01 GMT) Full text and rfc822 format available.

Message #25 received at 21698 <at> debbugs.gnu.org (full text, mbox):

From: Andy Wingo <wingo <at> pobox.com>
To: Matt Wette <matthew.wette <at> verizon.net>
Cc: Ludovic Courtès <ludo <at> gnu.org>, 21698 <at> debbugs.gnu.org
Subject: Re: bug#21698: accessing multiple flagged values with (ice-9
 getopt-long)
Date: Sat, 25 Jun 2016 10:07:01 +0200
On Sat 25 Jun 2016 02:12, Matt Wette <matthew.wette <at> verizon.net> writes:

> Could you at the least add a reference to SRFI-37 in the section on
> (ice-9 getopt-long), in case you don’t go further — e.g., replace it?

Done (in master, will backport later).

Andy




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 23 Jul 2016 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 334 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.