[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bug in getopt-long?
From: |
Daniel Skarda |
Subject: |
Bug in getopt-long? |
Date: |
28 Jul 2001 18:32:07 +0000 |
User-agent: |
Gnus/5.0806 (Gnus v5.8.6) Emacs/20.6 |
Hello,
I found that I quite do not understand getopt-long - or to be exact -
`predicate' in getopt-long specification. Imagine this code:
(define (test1 . args)
(getopt-long args
`((test (value #t) (predicate ,(lambda (x) (string-match "^[0-9]+$"
x)))))))
(define (test2 . args)
(getopt-long args
`((test (value #t)))))
(test1 "foo" "bar" "--test=123")
-=> '((() "bar") (test . "123")
(test1 "foo" "bar" "--test=foo")
[error] option predicate failed: test
(test2 "foo" "bar" "--test=foo")
-=> '((() "bar") (test . "foo"))
(test2 "foo" "bar")
-=> '(() "bar"))
(test1 "foo" "bar")
[error] option predicate failed: test !!! HUH !!!
Huh! It looks like that presence of `predicate' implies that argument is
required. I have not studied (ice-9 getopt-long) module sources but this
strange behaviour is not documented (not even expected :-)
IMHO there should be (getopt-long.scm:339) ...
(define make-user-predicate
(lambda (pred)
(lambda (spec)
(let ((val (option-spec->value spec)))
(if (and val (not (pred val)))
(error "option predicate failed:" (option-spec->name spec))
#t)))))
... but I am not sure - I do not know what author had in the mind (hope he
read these lines :)
D.
ps: few hours after discovering above bug I found another:
(define (test3 . args)
(getopt-long args
'((foo (value optional) (single-char #\f))
(bar))))
(test3 "prg" "--foo" "fooval" "--bar")
-=> ((()) (bar . #t) (foo . "fooval")) ; OK
(test3 "prg" "-f" "fooval" "--bar")
-=> ((()) (bar . #t) (foo . "fooval")) ; OK
(test3 "prg" "-f" "--bar")
-=> ((()) (bar . #t) (foo . #t) ; OK
(test3 "prg" "--foo" "--bar")
-=> ((()) (foo . "--bar")) ; HUH??? - BUG ??
(test3 "prg" "--bar" "-f")
-=> ((()) (foo . #t) (bar . #t)) ; OK
(test3 "prg" "--bar" "--foo")
[error] Not enough options ; HUH??? Value is
optional!
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Bug in getopt-long?,
Daniel Skarda <=