From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.bugs Subject: bug#21698: accessing multiple flagged values with (ice-9 getopt-long) Date: Fri, 24 Jun 2016 16:53:46 +0200 Message-ID: <878txufxj9.fsf@pobox.com> References: <0B36F95D-923F-465F-A7CA-52C98F58AFC7@verizon.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1466780065 30217 80.91.229.3 (24 Jun 2016 14:54:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 24 Jun 2016 14:54:25 +0000 (UTC) Cc: ludo@gnu.org, 21698@debbugs.gnu.org To: Matt Wette Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Fri Jun 24 16:54:15 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 1bGSUn-0007cx-OQ for guile-bugs@m.gmane.org; Fri, 24 Jun 2016 16:54:14 +0200 Original-Received: from localhost ([::1]:44089 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSUm-0006py-Vu for guile-bugs@m.gmane.org; Fri, 24 Jun 2016 10:54:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSUe-0006ck-5J for bug-guile@gnu.org; Fri, 24 Jun 2016 10:54:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGSUc-0006Dk-Pz for bug-guile@gnu.org; Fri, 24 Jun 2016 10:54:04 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42099) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSUc-0006DO-Ml for bug-guile@gnu.org; Fri, 24 Jun 2016 10:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bGSUc-00056i-Ef for bug-guile@gnu.org; Fri, 24 Jun 2016 10:54:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andy Wingo Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 24 Jun 2016 14:54: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.146678003719621 (code B ref 21698); Fri, 24 Jun 2016 14:54:02 +0000 Original-Received: (at 21698) by debbugs.gnu.org; 24 Jun 2016 14:53:57 +0000 Original-Received: from localhost ([127.0.0.1]:54436 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGSUW-00056O-KM for submit@debbugs.gnu.org; Fri, 24 Jun 2016 10:53:56 -0400 Original-Received: from pb-sasl2.pobox.com ([64.147.108.67]:61541 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGSUV-00056G-IB for 21698@debbugs.gnu.org; Fri, 24 Jun 2016 10:53:55 -0400 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id 3D42B21F38; Fri, 24 Jun 2016 10:53:54 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=ErUm83TP+TjZKGNvSYIoiWtnM+k=; b=HlCH7H ZwUZ4PSPPhysip33EYCq/URq1rPRySnkhIiKeBDMNOeRMZqfPfpgxCOxxDWIYhVt j3HvoQ/A1APo55mlyeNMNveNJRcAeJiWLgSZpuHnm3hUee72K87aukeA21mJr2hR 62Oawu197MqKs1fBNP/MkBAaj2ilbc60IzJFw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=VrppGeCEvEVsFr7eYUYni2EV91wXezBf 1w/tgHj5tvjziv4gmRUumGVZRJ8vu5yD8Hu7JSB9outopD2bg5iD+ray2y+Lsrao ShNDXzvyIiBeBbKnHKPY8Di2mOd5Ie1eBiwDbCp31woL8ha6NjU9+fuzqX45bgvc VlBaNgvy5uc= Original-Received: from pb-sasl2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id 3509221F35; Fri, 24 Jun 2016 10:53:54 -0400 (EDT) Original-Received: from clucks (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl2.pobox.com (Postfix) with ESMTPSA id 37DC221F34; Fri, 24 Jun 2016 10:53:53 -0400 (EDT) In-Reply-To: <0B36F95D-923F-465F-A7CA-52C98F58AFC7@verizon.net> (Matt Wette's message of "Sat, 17 Oct 2015 10:05:53 -0700") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) X-Pobox-Relay-ID: 781AB62E-3A1B-11E6-AF8A-28A6F1301B6D-02397024!pb-sasl2.pobox.com 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:8223 Archived-At: 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 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