Kaz Kylheku
4/9/2015 1:50:00 PM
On 2015-04-09, Luut <luut@example.com> wrote:
> Pascal Costanza wrote:
>> On 09/04/2015 10:59, jarausch@skynet.be wrote:
>
>>> The following code gives a warning that 'foo' in the declare
>>> declaration is unknown - why, and how to fix this?
>>>
>>> (flet ((foo (parm)
>>> (declare (inline foo)) ;;; <<<< style warning undefined function FOO
>>> (print parm)))
>>> (print (foo "hello")))
>>
>> The declaration has to be in the correct scope:
>>
>> (flet ((foo (parm) (print parm)))
>> (declare (inline foo))
>> (print (foo "hello")))
>
> Alternatively, use LABELS instead of FLET. (In my humble opinion,
> LABELS is what you want 99% of the time anyway.)
99% of the time it doesn't matter because the local function is neither
recursive, nor does it have to call another function of the same name
in an outer scope.
Arguably, when it doesn't matter, it seems that there is nevertheless some
justification in choosing the variant with a less encompassing scope. Or maybe
the one with the shorter name.
For instance, when it doesn't matter, you probably use LET rather than LET*.
Why expose forms to scopes that they don't need, right? Though if the names
of these two were reversed, you might still choose LET over LET* because of the
shorter name. FLET is also a nice name, not only a short one: function-let.
When it does matter, you want FLET about 100% of the time when a local function
FOO must call an outer function FOO, and you want LABELS 100% of the time when
a local function must call itself, or when two or more are mutually recursive.
(If you need to do both, you can split the function into a recursive part
with LABELS which has a different name, and a FLET interface to that.)