[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Binding the same variable twice in a single form

    The draft I have (dated June 20, 1989) doesn't specifically mention the
    consequences of specifying a variable twice in the same
    MULTIPLE-VALUE-BIND or LET form.  Were we to specify it, I expect we
    would say that "the consequences are unspecified", which means that the
    standard doesn't proscribe a particular behavior but it can't cause a
    fatal error.  I doubt if any implementation would violate this.  If you
    don't use the duplicated variable then you shouldn't have a problem.

    In the case of IGNORE variables, the portable way to do this is with the
    IGNORE declaration:

              (DECLARE (IGNORE VAL1 VAL2))
              <use X somehow>)

    I can't think of any other reason why you would want to bind the same
    variable twice in the same form, so the larger question should be moot.

At the risk of sounding a bit repetitive I would like to refresh the memory
of the ANSI CommonLisp committee with a similar issue that I brought up at
least a year ago. I would have just forwarded a copy of an old message I sent
but it is burried in an archived babyl file and I don't have the time to
resurrect it. So I will be brief and just restate the issue.

There are actually TWO different kinds of IGNORE behavior which are desirable
in CommonLisp while there is currently only ONE (official) mechanism.
One desired behavior is to declare that a variable SHOULD not be used while
the other desired behavior is to declare that a variable MIGHT not be used.
In the former, if you use a variable that is declared to be ignored then you
deserve an error message. This is the behavior that most compilers implement.
In the later, if you use a variable that is declared to be ignored you don't
get an error message; the main reason for using the latter is to avoid having
the compiler issue you a warning when you DON'T use a variable that you have
not declared to be ignored. This is usefull for cases when you can't predict
whether you will or won't access a variable. This situation can arrise for
instance when you create a general purpose macro for executing a form in a
lexical environment with certain lexical variables `implicitly' visable.
To wit:

(defmacro with-my-usefull-environment (&body body)
 `(let ((x (foo))
        (y (bar))
        (z (baz)))

(with-my-usefull-environment (sqrt (+ (* x x) (* y y) (* z z))))


(with-my-usefull-environment (sqrt (+ (* x x) (* y y))))

where z is not used.

I hope that the ANSI CommonLisp Committee addresses this issue before CommonLisp
gets frozen in stone.