Email list hosting service & mailing list manager

Optional option argument Shiro Kawai (07 Jul 2020 02:44 UTC)
Re: Optional option argument Marc Nieper-Wißkirchen (07 Jul 2020 09:35 UTC)
Re: Optional option argument Anthony Carrico (08 Jul 2020 16:49 UTC)
(missing)
Re: Optional option argument Anthony Carrico (08 Jul 2020 23:41 UTC)
Re: Optional option argument John Cowan (08 Jul 2020 23:43 UTC)
Re: Optional option argument Anthony Carrico (09 Jul 2020 00:05 UTC)
Re: Optional option argument John Cowan (09 Jul 2020 00:07 UTC)
Re: Optional option argument Anthony Carrico (09 Jul 2020 00:18 UTC)
Re: Optional option argument John Cowan (09 Jul 2020 00:22 UTC)
Re: Optional option argument Arthur A. Gleckler (30 Nov 2020 19:24 UTC)
Re: Optional option argument Anthony Carrico (30 Nov 2020 21:12 UTC)
Re: Optional option argument Arthur A. Gleckler (01 Dec 2020 00:56 UTC)
Re: Optional option argument Eugenio Montano (01 Dec 2020 01:50 UTC)
Re: Optional option argument Arthur A. Gleckler (01 Dec 2020 01:57 UTC)
Re: Optional option argument Anthony Carrico (01 Dec 2020 14:18 UTC)
Re: Optional option argument Shiro Kawai (08 Jul 2020 19:27 UTC)
Re: Optional option argument Anthony Carrico (08 Jul 2020 23:57 UTC)
Fwd: Optional option argument Arthur A. Gleckler (07 Jul 2020 17:34 UTC)
Re: Fwd: Optional option argument Anthony Carrico (08 Jul 2020 16:10 UTC)
Re: Fwd: Optional option argument Arthur A. Gleckler (08 Jul 2020 19:29 UTC)

Re: Optional option argument Marc Nieper-Wißkirchen 07 Jul 2020 09:34 UTC

Whatever SRFI 37 does, for the user it should be compatible with GNU's
getopt_long, which means that optional arguments to long options have
to use the '=' syntax. And optional arguments to short options have to
be in the same argv element according to the documentation to GNU's
getopt.

So from your description, it seems that Guile gets it wrong, at least morally.

I'd vote for a post-finalization note as well, saying that SRFI 37
intends to follow the POSIX standard with the relevant GNU extensions.

Marc

Am Di., 7. Juli 2020 um 04:44 Uhr schrieb Shiro Kawai <xxxxxx@gmail.com>:
>
> The spec allows an option to have "required" option-argument and/or "optional" option argument, but it is not clear how optional option argument is recognized.  For example, if you accept a long option "--bar" that takes an optional argument.  Should a command-line args '("--bar" "abc") be recognized as the option "--bar" taking an argument "abc", or the option bar "--bar" without an argument and an operand "abc"?
>
> If the command-line args is '("--bar=abc"), it is clear that the option "--bar" takes an argument "abc".  And indeed, the reference implementation is written so that it only recognizes an optional option argument when it appears in the same string of the argument itself (connected with '=' for the long options, and right after the last option character for the short options).
>
> gosh> (args-fold '("--ii" "the-argument")
>                  (list (option '("ii") #f #t   ; takes optional argument
>                                (lambda (opt name arg result)
>                                  arg)))
>                  (lambda args (error "unrecognized"))
>                  (lambda args #f)
>                  #f)
> #f
> gosh> (args-fold '("--ii=the-argument")
>                  (list (option '("ii") #f #t  ; takes optional argument
>                                (lambda (opt name arg result)
>                                  arg)))
>                  (lambda args (error "unrecognized"))
>                  (lambda args #f)
>                  #f)
> "the-argument"
>
> If the option takes required argument, both forms are recognized:
>
> gosh> (args-fold '("--ii" "the-argument")
>                  (list (option '("ii") #t #f
>                                (lambda (opt name arg result)
>                                  arg)))
>                  (lambda args (error "unrecognized"))
>                  (lambda args #f)
>                  #f)
> "the-argument"
> gosh> (args-fold '("--ii=the-argument")
>                  (list (option '("ii") #t #f
>                                (lambda (opt name arg result)
>                                  arg)))
>                  (lambda args (error "unrecognized"))
>                  (lambda args #f)
>                  #f)
> "the-argument"
>
> Short options behave similarly.
>
> So, this behavior may be the author's intention, but this behavior isn't clear from the SRFI text.  If it's in the boundary of errata, it's nice to be clarified.
>
> It looks like many Scheme implementations adopt the reference implementation and behave the same, but Guile behaves differently *only for short options*:
>
> xxxxxx@(guile-user)> (args-fold '("-I" "the-argument")
>                                 (list (option '(#\I) #f #t
>                                               (lambda (opt name arg result)
>                                                 arg)))
>                                 (lambda args (error "unrecognized" args))
>                                 (lambda args #f)
>                                 #f)
> $7 = "the-argument"
> xxxxxx@(guile-user)> (args-fold '("-Ithe-argument")
>                                 (list (option '(#\I) #f #t
>                                               (lambda (opt name arg result)
>                                                 arg)))
>                                 (lambda args (error "unrecognized" args))
>                                 (lambda args #f)
>                                 #f)
> $8 = "the-argument"
>
> While:
>
> gosh> (args-fold '("-I" "the-argument")
>                  (list (option '(#\I) #f #t
>                                (lambda (opt name arg result)
>                                  arg)))
>                  (lambda args (error "unrecognized" args))
>                  (lambda args #f)
>                  #f)
> #f
> gosh> (args-fold '("-Ithe-argument")
>                  (list (option '(#\I) #f #t
>                                (lambda (opt name arg result)
>                                  arg)))
>                  (lambda args (error "unrecognized" args))
>                  (lambda args #f)
>                  #f)
> "the-argument"
>
>
>
>