Summary
args egg: can't use an option called "name"
Metadata
- Id: 5bc1128978e43c734134937a92ea11ddb561b50b
- Trac id: 891
- Type: defect
- Reporter: dreamtime
- Owner: zbigniew
- Cc:
- Status: closed
- Component: extensions
- Estimated difficulty:
- Resolution: fixed
- Priority: major
- Milestone:
- Version: 4.7.x
- Changetime: 2012-07-31 21:39:23 UTC
- Created: 2012-07-30 20:56:11 UTC
- Keywords:
Description
When using the args egg, trying to use an option called "name" fails because of a conflict with the args egg's own internal "name" variable.
From the args egg documentation: "BODY is an option-processor as defined in SRFI 37, and has access to the variables OPT (the current #<option>), NAME (the option name) and ARG (argument value or #f)."
At line 12 in the code example given below, everything works as intended, with the "name" variable being set to "foo" when the program is called as: ./myprogram.csi --name=foo
But after line 19, the "name" variable is empty again.
If the "name" variable is changed from "name" to anything else, like "xyz", it works.
01 (define name "") 02 03 ... 04 05 (define opts 06 (list (args:make-option 07 ... 08 (args:make-option 09 (n name) 10 (required: "NAME") 11 "description of this option goes here" 12 (set! name arg)) 13 ...) 14 15 (define (get-args) 16 (receive (options operands) 17 (args:parse (command-line-arguments) 18 opts 19 #:unrecognized-proc unrecognized-option) 20 (check-args options operands) 21 (values name foo bar baz)))
Changes and comments
[2012-07-31 21:24:07 UTC] sjamaan changed status from new to assigned
[2012-07-31 21:24:07 UTC] sjamaan set owner to zbigniew
[2012-07-31 21:24:07 UTC] sjamaan removed milestone 4.8.0
[2012-07-31 21:24:07 UTC] sjamaan wrote:
The args:make-option macro is unhygienic by design. This is documented:
BODY is an option-processor as defined in SRFI 37, and has access to the variables OPT (the current #<option>), NAME (the option name) and ARG (argument value or #f).
I'll leave it to Jim to decide whether close this ticket "invalid" or to come up with an alternative, hygienic, macro.
[2012-07-31 21:39:23 UTC] dreamtime changed status from assigned to closed
[2012-07-31 21:39:23 UTC] dreamtime set resolution to fixed
[2012-07-31 21:39:23 UTC] dreamtime wrote:
Looks like the problem was indeed with the global variable called "name". Renaming it to "my-name" works, while still allowing a command line option called "name".