Opened 8 years ago

Closed 8 years ago

#1289 closed defect (fixed)

getopt-long (value #f) inconsistent with documentation

Reported by: Norman Gray Owned by:
Priority: major Milestone: someday
Component: extensions Version: 4.10.x
Keywords: getopt-long Cc:
Estimated difficulty:

Description

The documentation for getopt-long says that

(value FLAG [(PROPERTY VALUE) ...])
If FLAG is #t, the option requires a value;...

and

(predicate FUNC)
If the option accepts a value (i.e. you specified (value #t) for this option)...

These would seem to indicate that (value #t (predicate ,string)) would be acceptable, but the following program fails:

(use getopt-long)

(define grammar
  `((test (single-char #\t)
          (value #t ;(required "REQ")
                 (predicate ,string?)))))

(write
 (getopt-long '("my-prog" "-t" "foo")
              grammar))
(newline)

Result:

% csi getopt-long-demo.scm

CHICKEN
(c) 2008-2015, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.10.0 (rev b259631)
macosx-unix-clang-x86-64 [ 64bit manyargs dload ptables ]
compiled 2015-08-04 on yves.more-magic.net (Linux)

; loading getopt-long-demo.scm ...
; loading /Data/tools/chicken-4.10.0/lib/chicken/7/getopt-long.import.so ...
; loading /Data/tools/chicken-4.10.0/lib/chicken/7/chicken.import.so ...
; loading /Data/tools/chicken-4.10.0/lib/chicken/7/data-structures.import.so ...
; loading /Data/tools/chicken-4.10.0/lib/chicken/7/srfi-1.import.so ...
; loading /Data/tools/chicken-4.10.0/lib/chicken/7/srfi-13.import.so ...
; loading /Data/tools/chicken-4.10.0/lib/chicken/7/srfi-14.import.so ...
; loading /Data/tools/chicken-4.10.0/lib/chicken/7/matchable.import.so ...
; loading /Data/tools/chicken-4.10.0/lib/chicken/7/lolevel.import.so ...
; loading /Data/tools/chicken-4.10.0/lib/chicken/7/getopt-long.so ...
; loading /Data/tools/chicken-4.10.0/lib/chicken/7/matchable.so ...

Error: invalid value specification : (#t (predicate #<procedure (string? x463)>))

Replacing the #t with (required "REQ") works as expected.

Change History (3)

comment:1 Changed 8 years ago by Ivan Raikov

Thanks for reporting this issue. I have added a clarification of the semantics of the value property to the getopt-long documentation.

comment:2 Changed 8 years ago by Norman Gray

Looks good to me!

(do I close this issue or do you?)

comment:3 Changed 8 years ago by sjamaan

Resolution: fixed
Status: newclosed

Looks like it's fixed then

Note: See TracTickets for help on using tickets.