[Openmcl-devel] Undefined function: muting the compiler

Gary Byers gb at clozure.com
Tue Sep 28 17:29:34 PDT 2010


Warnings about undefined functions are deferred until the end of the "compilation
unit"; COMPILE-FILE establishes a compilation unit and (in CCL at least) LOAD does
as well.  A deferred warning about an undefined function is effectively cancelled
if the function name in question is later found to be defined as a function.

So:

(with-compilation-unit ()
   (load "home:A")
   (load "home:B"))

will suppress warnings about functions that're referenced before they're
defined, as long as they're defined within the extent of the outermost
compilation unit (or the innermost compilation unit that was established
with the :OVERRIDE T option; see CLHS or CLtL2 for details.)

In cases where it isn't possible to use WITH-COMPILATION-UNIT (where it's
known that some function F will be defined at runtime but wasn't defined
at compile time or as part of the same compilation unit as its caller(s)),
an undefined-function warning can be suppressed if a declaration of F's
functional type is in effect at the point of the call.

? (defun foo (x)
   (declare (ftype function bar))
   (bar x))
FOO

That's basically saying that #'BAR is expected to be a function; that's
different from saying:

? (defun foo (x)
   (declare (type function bar))
   (bar x))

which is an assertion about the type of the variable BAR (and would, all other
things being equal, likely lead to a warning here.)

The complex form of the FUNCTION type specifier can also be used and is sometimes
useful:

? (defun foo (x)
   (declare (ftype (function (t t) t) bar))
   (bar x))
;Compiler warnings :
;   In FOO: In the call to BAR with arguments (X),
;     1 argument was provided, but at least 2 are required
;     by the FTYPE declaration of BAR
FOO

That says that #'BAR is a function of 2 arguments (of universal type)
and that it returns a single value (also of type T); calling it with
one argument generates a warning when that declaration's in effect.




On Tue, 28 Sep 2010, Michael Minerva wrote:

> Hey Paul,
>
> I think our issue might be better described with an example with three files:
>
> First, we have an init.lisp that contains:
>
> (load "home:A")
> (load "home:B")
>
> Then, A.lisp:
>
> (defun a-func()
>  (b-func))
>
> Finally, b.lisp:
>
> (defun b-func ()
>  (print "B-FUNC!"))
>
> When you execute the init file you will get this warning:
>
> ;Compiler warnings for "home:A.lisp.newest" :
> ;   In A-FUNC: Undefined function B-FUNC
>
> Most of the time we would try to declare b-func in a file that is loaded before a.lisp gets loaded, but in a few cases this is impossible.  Is there anyway to avoid this type of warning?  Thanks.
>
> --Mike
> On Sep 28, 2010, at 4:48 PM, Paul Krueger wrote:
>
>> Alex,
>>
>> I wonder if there isn't something else going on for you. I was pretty sure that I didn't see the behavior you describe, so I created a simple example file containing two defun's that each reference the other to test my memory. Neither load nor compile-file gave any kind of warning for this example. You DO get a warning if you just open the file in the IDE and do an "execute all" on it, but I sort of expect that.
>>
>> Paul
>>
>>
>> On Sep 28, 2010, at 5:20 PM, Alexander Repenning wrote:
>>
>>> This is just a silly but general CL question but I wonder how people are handling it. If you are loading a file containing, say, function a and b and a calling b and for some reason you cannot move up b to be located before a you will get the compiler warning In A: Undefined function B
>>>
>>> Not a big deal but it is really nice to get rid of all compiler warnings if possible. I just cant find relevant stuff in CLTL2. I would imagined that one could do something like
>>>
>>> (proclaim '(type function b)) or (proclaim '(function b))
>>>
>>> but that does not appear to work
>>>
>>> any suggestions?
>>>
>>> Alex
>>>
>>>
>>>
>>> _______________________________________________
>>> Openmcl-devel mailing list
>>> Openmcl-devel at clozure.com
>>> http://clozure.com/mailman/listinfo/openmcl-devel
>>
>> _______________________________________________
>> Openmcl-devel mailing list
>> Openmcl-devel at clozure.com
>> http://clozure.com/mailman/listinfo/openmcl-devel
>>
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>



More information about the Openmcl-devel mailing list