4

I have a function that I'm trying to compile, but I've been pulling my hair out for the last 30 minutes trying to figure out why this code is giving me a Undeclared free variable error. I'm using Emacs, and cannot decipher why I'm getting this error.

(defun pretty-all(res diff)
  (let* ((v-list (blank-unit-list res))
         (c-list (blank-unit-list res)))
    (complete-fill c-list v-list res (total-res res) diff)
    (format t
            "Resistance is ~S~% Voltage is ~S~% Current is ~S~%"
            res v-list c-list)))

blank-unit-list , complete-fill , total-res are all my custom-defined functions.

I'm pretty sure this error is related to how I structured my code, but as I've said before, I can't figure out what.


Copied from Emacs:

3 compiler notes:

CircuitFunctions.lisp:61:64:
  warning: Undeclared free variable RES

CircuitFunctions.lisp:61:70:
  warning: Undeclared free variable V-LIST

CircuitFunctions.lisp:61:81:
  warning: Undeclared free variable C-LIST

Compilation failed.
Jacob Schoen
  • 14,034
  • 15
  • 82
  • 102
Zchpyvr
  • 1,119
  • 3
  • 12
  • 26
  • show us the exact error? – bmargulies Jun 08 '12 at 00:23
  • 2
    If I put empty definitions for `complete-fill`, `blank-unit-list`, and `total-res` in a file and add the above code for `pretty-all`, I can byte-compile it without any errors. – Thomas Jun 08 '12 at 00:39
  • That's really weird..... – Zchpyvr Jun 08 '12 at 00:42
  • Which platform and version of Emacs are you using? Also: if those warnings are showing line:column numbers, I can't see how they could match up to the function you have shown. – phils Jun 08 '12 at 08:20
  • I've compiled `complete-fill` and the method works, but this method can't. I actually using lispbox and believe I am using common lisp. – Zchpyvr Jun 08 '12 at 12:05
  • Edited question to remove elisp references. – phils Jun 08 '12 at 16:34

2 Answers2

0

If you are using SLIME (and it looks as if you may be, as you're using lispbox), there should be a way of going from a compiler note to where in the source it occurred. I don't remember the exact key combination (I could probably press it if you put an emacs with slime in front of me, but that doesn't mean I consciously remember what it is, unfortunately). Checking what key slime-next-error is bound to would probably be helpful and there may be something in the SLIME menu).

From looking at the line numbers in the compiler notes (I think the :61:64 and the like is source line and column), the actual emitted errors are not matching up (at all) to the code you have pasted. There is no line I can see that have all of v-list, res and c-list in that order. That might be due to a macro expansion, though (as a side note, it looks as if complete-fill either is a macro or destructively modifies two of its arguments).

Vatine
  • 20,782
  • 4
  • 54
  • 70
  • Actually, I changed the order to test the error, and I forgot to alter the code accordingly. The order of the variables, then have little to do with the error. For clarity's sake, I edited the question to reflect congruity. – Zchpyvr Jun 12 '12 at 01:32
0

Following wvxvw's suggestion that my code might have a missing parens somewhere, I scrolled through my file with C-M-f. It passed through without a problem and by now I was starting to give up. Lastly, just to make sure, I copied the code from this question and replaced my previous function with the one here. Somehow it works now. I don't know what it was that caused the problem, but it functions correctly now. Thanks everyone for their input.

Zchpyvr
  • 1,119
  • 3
  • 12
  • 26