Opened 7 years ago

Closed 7 years ago

#891 closed defect (fixed)

args egg: can't use an option called "name"

Reported by: dreamtime Owned by: zbigniew
Priority: major Milestone:
Component: extensions Version: 4.7.x
Keywords: Cc:
Estimated difficulty:

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)))

Change History (2)

comment:1 Changed 7 years ago by sjamaan

  • Milestone 4.8.0 deleted
  • Owner set to zbigniew
  • Status changed from new to assigned

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.

comment:2 Changed 7 years ago by dreamtime

  • Resolution set to fixed
  • Status changed from assigned to closed

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".

Note: See TracTickets for help on using tickets.