Lisp HUG Maillist Archive

unused variable warning

It seems to me that I used to get an assumed special warning in
something like the following, although I don't have an older version
handy to check with. I'm on LWM 5.1.1


CL-USER 1 > (defun test ()
              (dolist (x '(1 2 3 4 5))
                stray-variable
                x))
TEST

CL-USER 2 > (test)
NIL

CL-USER 3 > (compile 'test)
TEST
NIL
NIL

Even if it's not the default to warn (I can see where the reference
would be removed since it doesn't have an effect), is there a way to
get a warning on this kind of code? Thanks!

-- 
=====================
Joshua Taylor
tayloj@cs.rpi.edu, jtaylor@alum.rpi.edu

"A lot of good things went down one time,
 back in the goodle days."
 John Hartford


Re: unused variable warning

On Thu, Jun 12, 2008 at 4:14 AM, Joshua TAYLOR <tayloj@cs.rpi.edu> wrote:
>
> It seems to me that I used to get an assumed special warning in
> something like the following, although I don't have an older version
> handy to check with. I'm on LWM 5.1.1
>
>
> CL-USER 1 > (defun test ()
>              (dolist (x '(1 2 3 4 5))
>                stray-variable
>                x))
> TEST


Hmmm, I'm not sure if this could ever have warned about stray-variable
being assumed special.
>From the CLHS entry on dolist, in the Notes Section;

"go may be used within the body of dolist to transfer control to a
statement labeled by a tag."

Which means that the 'stray-variable' symbol in your function is being
used as a tag.
Without the dolist everything does work as you expect.


(defun foo ()
  foobar)

;;;*** Warning in FOO: FOOBAR assumed special


cheers,
 sean.


Re: unused variable warning

On Thu, Jun 12, 2008 at 4:33 AM, Sean Ross <rosssd@gmail.com> wrote:
> On Thu, Jun 12, 2008 at 4:14 AM, Joshua TAYLOR <tayloj@cs.rpi.edu> wrote:
>>
>> It seems to me that I used to get an assumed special warning in
>> something like the following, although I don't have an older version
>> handy to check with. I'm on LWM 5.1.1
>>
>>
>> CL-USER 1 > (defun test ()
>>              (dolist (x '(1 2 3 4 5))
>>                stray-variable
>>                x))
>> TEST
>
>
> Hmmm, I'm not sure if this could ever have warned about stray-variable
> being assumed special.
> From the CLHS entry on dolist, in the Notes Section;
>
> "go may be used within the body of dolist to transfer control to a
> statement labeled by a tag."
>
> Which means that the 'stray-variable' symbol in your function is being
> used as a tag.
> Without the dolist everything does work as you expect.
>
>
> (defun foo ()
>  foobar)
>
> ;;;*** Warning in FOO: FOOBAR assumed special
>
>
> cheers,
>  sean.
>

Ah, that's exactly it. Thanks. And to provide an example of the
behavior I'd expect in other situations:

CL-USER 1 > (defun test ()
              stray-variable
              (list 1 2 3))
TEST

CL-USER 2 > (compile 'test)
;;;*** Warning in TEST: STRAY-VARIABLE assumed special
TEST
((NIL #<CONDITIONS::SIMPLE-STYLE-WARNING 21D0AA6B>))
NIL

I'd just forgotten about that implicit tagbody within dolist. Thanks!

-- 
=====================
Joshua Taylor
tayloj@cs.rpi.edu, jtaylor@alum.rpi.edu

"A lot of good things went down one time,
 back in the goodle days."
 John Hartford


Updated at: 2020-12-10 08:43 UTC