From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.bugs Subject: bug#21698: accessing multiple flagged values with (ice-9 getopt-long) Date: Fri, 24 Jun 2016 08:21:11 -0700 Message-ID: <71713D65-96AD-4729-96AF-31828E3D3186@verizon.net> References: <0B36F95D-923F-465F-A7CA-52C98F58AFC7@verizon.net> <878txufxj9.fsf@pobox.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1466781744 25826 80.91.229.3 (24 Jun 2016 15:22:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 24 Jun 2016 15:22:24 +0000 (UTC) Cc: ludo@gnu.org, 21698@debbugs.gnu.org To: Andy Wingo Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Fri Jun 24 17:22:14 2016 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bGSvt-00078w-4f for guile-bugs@m.gmane.org; Fri, 24 Jun 2016 17:22:13 +0200 Original-Received: from localhost ([::1]:44274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSvs-0001xf-5o for guile-bugs@m.gmane.org; Fri, 24 Jun 2016 11:22:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSvm-0001wX-4b for bug-guile@gnu.org; Fri, 24 Jun 2016 11:22:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGSvi-0005P1-B9 for bug-guile@gnu.org; Fri, 24 Jun 2016 11:22:04 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42128) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSvi-0005Ox-7b for bug-guile@gnu.org; Fri, 24 Jun 2016 11:22:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bGSvi-0005sJ-48 for bug-guile@gnu.org; Fri, 24 Jun 2016 11:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Matt Wette Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 24 Jun 2016 15:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21698 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 21698-submit@debbugs.gnu.org id=B21698.146678168122532 (code B ref 21698); Fri, 24 Jun 2016 15:22:02 +0000 Original-Received: (at 21698) by debbugs.gnu.org; 24 Jun 2016 15:21:21 +0000 Original-Received: from localhost ([127.0.0.1]:54465 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGSv3-0005rK-7J for submit@debbugs.gnu.org; Fri, 24 Jun 2016 11:21:21 -0400 Original-Received: from omr-m010e.mx.aol.com ([204.29.186.10]:34481) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGSv1-0005r3-FT for 21698@debbugs.gnu.org; Fri, 24 Jun 2016 11:21:19 -0400 Original-Received: from mtaout-mca02.mx.aol.com (mtaout-mca02.mx.aol.com [172.26.221.78]) by omr-m010e.mx.aol.com (Outbound Mail Relay) with ESMTP id D635B38001AE; Fri, 24 Jun 2016 11:21:13 -0400 (EDT) Original-Received: from nautilus.championbroadband.com (nautilus.championbroadband.com [216.165.228.109]) by mtaout-mca02.mx.aol.com (MUA/Third Party Client Interface) with ESMTPA id E1BAB380000AD; Fri, 24 Jun 2016 11:21:12 -0400 (EDT) In-Reply-To: <878txufxj9.fsf@pobox.com> X-Mailer: Apple Mail (2.2104) x-aol-global-disposition: G x-aol-sid: 3039ac1add4e576d4fe83e37 X-AOL-IP: 216.165.228.109 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8226 Archived-At: Thanks for the pointer. I can work with SRFI-37. I am OK w/ rejection = of the patch. =E2=80=94 Matt > On Jun 24, 2016, at 7:53 AM, Andy Wingo wrote: >=20 > Hi Matt, >=20 > 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. >=20 > https://www.gnu.org/software/guile/manual/html_node/SRFI_002d37.html >=20 > Ludovic, second opinions? >=20 > Andy >=20 > On Sat 17 Oct 2015 19:05, Matt Wette = writes: >=20 >> This is in reference to guile-2.0.11. >>=20 >> The (ice-9 getopt-long) module does not provide a process for >> accessing multiple command line arguments. >>=20 >> A patch for ice-9/getopt-long.scm is attached which adds the = procedure >> getopt-ref/many to access multiple argument values. >>=20 >> The following program and results illustrate the use of the current >> getopt-ref and the proposed getopt-ref/many: >>=20 >> mwette$ ./gotest.scm -f foo1 -b bar1 -f foo2 baz1 baz2 >>=20 >> program arguments: >>=20 >> ("./gotest.scm" "-f" "foo1" "-b" "bar1" "-f" "foo2" "baz1" "baz2") >>=20 >> getopt using option-ref: >>=20 >> foo: "foo2" >>=20 >> bar: "bar1" >>=20 >> getopt using option-ref/many: >>=20 >> foo: ("foo1" "foo2") >>=20 >> bar: "bar1" >>=20 >> where >>=20 >> mwette$ cat gotest.scm=20 >>=20 >> #!/opt/local/bin/guile >>=20 >> !# >>=20 >> (use-modules (ice-9 getopt-long)) >>=20 >> (define spec >>=20 >> '((foo (single-char #\f) (value #t)) >>=20 >> (bar (single-char #\b) (value #t)))) >>=20 >> (let* ((args (program-arguments)) >>=20 >> (opts (getopt-long args spec))) >>=20 >> (simple-format #t "program arguments:\n") >>=20 >> (simple-format #t "~S\n" args) >>=20 >> (simple-format #t "\ngetopt using option-ref:\n") >>=20 >> (simple-format #t "foo: ~S\n" (option-ref opts 'foo #f)) >>=20 >> (simple-format #t "bar: ~S\n" (option-ref opts 'bar #f)) >>=20 >> (simple-format #t "\ngetopt using option-ref/many:\n") >>=20 >> (simple-format #t "foo: ~S\n" (option-ref/many opts 'foo #f)) >>=20 >> (simple-format #t "bar: ~S\n" (option-ref/many opts 'bar #f)) >>=20 >> ) >>=20 >>=20 >>=20 >> *** 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) =3D> = "/usr/include" >> ;;; (option-ref (getopt-long ...) 'not-a-key! 31) =3D> 31 >>=20 >> + ;;; (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=3D/usr/include" >> + ;;; "--x-includes=3D/opt/includd" "--" "-fred" = "foo2" "foo3") >> + ;;; grammar) >> + ;;; (option-ref/many (getopt-long ...) 'x-includes 42) >> + ;;; =3D> ("/usr/include" "/opt/include") >> +=20 >> ;;; Code: >>=20 >> (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)) >>=20 >> (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)) >>=20 >> (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)) >>=20 >> + (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)))))) >> +=20 >> ;;; getopt-long.scm ends here